开发者

SQL query - some kind of select distinct?

Suppose I have a log of Customers who come in on particular Days, like:

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

I need a quer开发者_运维知识库y that returns only the #s of those Customers who were in both on Tue and on Wed. In this case, only Cs # 01.


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


And using subqueries...

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜