SQL查询 - 某种选择不同?

时间:2009-11-03 20:12:03

标签: sql

假设我有特定日期的客户记录,例如:

Cs  day
--  ---
01  Tue
02  Tue
03  Wed
01  Wed
04  Thu
02  Thu

我需要一个只返回周二和周三两个客户的#的查询。在这种情况下,只有Cs#01。

2 个答案:

答案 0 :(得分:6)

select distinct c1.Cs
from Customers c1 
inner join Customers c2 on c2.Cs=c1.Cs
where c2.day='Tue' and c1.day='Wed'

答案 1 :(得分:0)

使用子查询...

Select distinct cs From Customers
Where Exists (Select * from Customers
              Where day = 'Tue')
  And Exists (Select * from Customers
              Where day = 'Wed')