收入低于凯瑟琳的教师姓名和人数

时间:2018-07-14 06:25:13

标签: mysql

显示教师人数和收入低于“凯瑟琳”的教师的姓名。 enter image description here

1 个答案:

答案 0 :(得分:0)

为什么不尝试一下,sql是如此简单

SELECT * FROM teacher WHERE salary <
 (SELECT salary FROM teachear WHERE name='Katherine')

OR

SELECT t1.* FROM teacher t1 
  JOIN teacher t2 ON t1.salary < t2.salary AND t2.name='atherine'

更新的答案。

通常名称和总数不能在同一级别显示,如果要执行此操作,可以使用GROUP_CONCAT将所有名称组合为一个记录

SELECT count(t.teacher_id) AS count,GROUP_CONCAT(t.name) as names
FROM  teacher t
WHERE t.teacher_id IN
(
SELECT t1.teacher_id FROM teacher t1 
  JOIN teacher t2 ON t1.salary < t2.salary AND t2.name='atherine'
)