调用特定的列

时间:2019-03-26 14:35:23

标签: mysql sql

我有一张桌子,就像这样:

enter image description here 问题是“给汤姆领导下的所有员工打电话:”

输出应为: enter image description here

3 个答案:

答案 0 :(得分:3)

是否总是要订购ID? 如果是这样,您想要的是选择ID比Tom的ID大的行

SELECT * FROM employees WHERE Id > (SELECT Id FROM employees WHERE Name = 'Tom');

答案 1 :(得分:2)

这是你在找什么吗?

SELECT t.*
FROM table t
WHERE t.id = (SELECT MAX(t1.id) 
              FROM table t1 
              WHERE t1.position = t.position AND t1.department = t.department
             );

答案 2 :(得分:1)

尝试一下:

select * 
from TABLE_NAME 
where Id > (select Id from TABLE_NAME where Name = 'Tom')