假设我有特定日期的客户记录,例如:
Cs day
-- ---
01 Tue
02 Tue
03 Wed
01 Wed
04 Thu
02 Thu
我需要一个只返回周二和周三两个客户的#的查询。在这种情况下,只有Cs#01。
答案 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')