查询集限制SQL数据库

时间:2016-08-08 04:03:13

标签: sql database subquery upperbound

Name      Gender     School        Position     Salary
-----------------------------------------------------------
Alex      Male       Computing     Lecturer      $80,000
Bob       Male       Mathematics   Lecturer      $60,000
Carol     Female     Mathematics   Lecturer     $100,000
Diana     Female     Computing     Lecturer      $60,000
Ewen      Male       Physics       Lecturer      $72,000
Fran      Female     Physics       Lecturer      $88,000
Gary      Male       Computing     Administrator $40,000
Humphry   Male       Mathematics   Lecturer      $72,000
Ivana     Female     Computing     Tutor         $12,000
Je        Male       Physics       Administrator $80,000
Kim       Female     Mathematics   Lecturer     $100,000
Lex       Male       Computing     Tutor         $12,000
Morris    Male       Engineering   Tutor         $15,000    

假设您只有统计界面,因此只有聚合查询才会成功。你知道戴安娜是一位女性计算机讲师。下面的问题探讨了在存在各种查询大小限制的情况下,我们如何使用推理来确定她的薪水。

假设存在满足的较低和较高查询大小限制 k jX(C)j N k k = 2.显示一系列可用于确定戴安娜薪水的查询。

这是一个学校问题,任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

一个带有条件SUM()

的agregated函数
 SELECT SUM(CASE WHEN Name = 'Diana' THEN Salary ELSE 0 END) as salary
 FROM YourTable

现在不知道什么是较低的查询大小。

SELECT Max(Salary)
FROM YourTable
WHERE School = 'computing'
  AND Gender = 'Female'
  AND Position = 'Lecturer'