我想用不同的列值执行相同的SQL查询,即:我有一个如下表:
+--------+-------+---------------+
| ENAME | EID | BASIC Salary |
+--------+-------+---------------+
| AAA | 111 | 12345 |
| BBB | 222 | 45678 |
| CCC | 333 | 8965 |
| DDD | 444 | 3654 |
| .............................. |
| ZZZ | 555 | 12345 |
+--------+-------+---------------+
从上表中,我想为一组员工获取EID
和Salary
。请建议我如何在不执行多次的情况下进行查询以获取上述数据。
答案 0 :(得分:2)
尝试此查询
SELECT ENAME, EID, Salary FROM <TABLENAME> WHERE ENAME IN ('AAA','DDD','ZZZ');
或
SELECT ENAME, EID, Salary FROM <TABLENAME1> WHERE ENAME IN (SELECT ENAME FROM <TABLENAME2> WHERE <CRITERIA>);
答案 1 :(得分:0)
基本的syntex是:
select columnname1, sum(columnname2) from tablename where condition.. group by columnname1
在这里,您将编写一个如下查询:
select EID, sum(salary) from table where EID in(101,102,103,104,...)
group by EID
这里,如果你想要200或300行数据,那么在sql中使用skip和limit。您将编写一个如下查询:
select EID, sum(salary) from table
group by EID limit 10 offset 0
其中limit是no记录而offset是跳过记录