-1

我是 sql 领域的新手,我有一些问题。

如下表

Table Name:EM

ID    name    Birth   High
1     Tom     11/23   65
2     Mary    11/23   65
3     Bill    03/02   55
4     Liny    01/08   45
5     Kevin   05/16   50
6     Lee     05/16   50

但我只需要如下数据

ID    name    Birth   High
1     Tom     11/23   65
2     Mary    11/23   65
3     Kevin   05/16   50
4     Lee     05/16   50

我用傻瓜sql来获取这样的数据

select * from em where birth = '11/23' and high = '65';
select * from em where birth = '05/16' and high = '50';

请教我如何在一条sql语句中得到结果,非常感谢。

4

5 回答 5

5

你想要 IN

select * from em where (birth, high) in (('11/23','65'),('05/16','50'));
于 2012-12-27T09:25:52.717 回答
4

用来OR组合它们:

select * from em where (birth = '11/23' and high = '65') or (birth = '05/16' and high = '50');
于 2012-12-27T09:26:53.733 回答
1

你可以从这里开始学习 SQL

使用INand在BETWEEN这里检查IN 的教程,并在此处检查 BETWEEN 的教程

这可能是您的查询

SELECT * FROM YOUR_TABLE WHERE COL1 IN (DATE_HERE,ID_HERE) AND/OR COL2 IN (DATE_HERE,ID_HERE)
于 2012-12-27T09:23:47.270 回答
0
IN operator is used for adding multiples values

select * from em where birth in ('11/23','05/16') and high in ('65','50');
于 2012-12-27T09:24:14.803 回答
0

您可以使用 "or","in" 运算符

像这样:

 select * from em 
 where 
  birth = '11/23' or birth = '05/16' 
  and high = '65' or  high = '50';
于 2012-12-27T09:25:04.667 回答