34,590
社区成员
发帖
与我相关
我的任务
分享
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' ,'上海', '美女'
--下面是添加的记录
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'))
--我用的查询语句:
select distinct area from @a a1 where not exists(select * from @a a2 where not exists(select * from @a a3 where a3.area=a1.area and a3.riqi=a2.riqi))
--上面的数据特殊,改一下
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 行)
*/
共有是啥意思?总数,每天的数量?
select count(*) from tb where riqi < '2007-10-31'
select riqi , count(*) from tb where riqi < '2007-10-31' group by riqi