[英]SQL Server : how to select the rows in a table with the same value on a column but some exact values on another column for the grouped rows
[英]SQL : select rows with value in some column and the value does is not contained in another table
有两张桌子
学生 :
ID | Name | Age
---+------+-----
1 | Alex | 19
2 | Matt | 23
3 | Ali | 19
动作 :
ACTIONID | Description
---------+---------------------------
1 | Alex hasn't paid yet
我想选择19岁的学生证。但是,不想选择其名称包含在“ Actions
表的描述列的任何行中的学生。
所以结果应该如下
ID: 3
怎么做? 有人可以帮我吗?
尝试这个:
SELECT student.ID
FROM Students student
WHERE 0 = (SELECT COUNT(*)
FROM Actions action
WHERE action.Description LIKE CONCAT('%', student.Name, '%')
AND student.Age = 19;
如果我理解你的问题。
select ID from Students where Age = 19
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.