繁体   English   中英

SQL:选择某列中具有值的行,而该值不包含在另一个表中

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM