riqi area info
2007-10-6 南京 房价
2007-10-6 上海 猪肉
2007-10-8 西安 工资
2007-10-8 南京 交通
2007-10-8 上海 美女
.
.
.
.
.
我如果要查找所有时间下共有的area。。这个SQL咋写啊。。假设时间是<2007-10-31
------解决方案--------------------
- SQL code
--上面的数据特殊,改一下declare @a table(riqi smalldatetime, area varchar(10), info varchar(10))insert @a select '2007-10-6', '南京', '房价' union all select '2007-10-6' ,'上海', '猪肉' union all select '2007-10-8' ,'西安', '工资' union all select '2007-10-8' ,'南京', '交通' union all select '2007-10-8' ,'上海', '美女' union all select '2007-10-9' ,'上海', '美女'select area from @a a where riqi<'2007-10-31' group by area having(count(1)=(select distinct count(distinct riqi) from @a where riqi<'2007-10-31'))--result/*area ---------- 上海(所影响的行数为 1 行)*/