日期:2014-05-17 浏览次数:20607 次
declare @a int,@b int,@c int,@d int,@e int,@f int,@h int,@g int
select @a=0,@b=0,@c=0,@d=0,@e=0,@f=0,@h=0,@g=0;
while @a!=3 or @b!=1 or @c!=2 or @d!=3 or @e!=3 or @f!=2 or @h!=2 or @g!=2
begin
if OBJECT_ID('tb')is not null
drop table tb;
with cte_a(id,cid,sid,name,ssex,birthday)
as
(select top(6)NEWID()as id,cid,sid,name,ssex,birthday from class order by NEWID())
select cid,sid,name,ssex,birthday into tb from cte_a
select @a=(select COUNT(cid) from tb where cid='0001')
,@b=(select COUNT(cid) from tb where cid='0002')
,@c=(select COUNT(cid) from tb where cid='0003')
,@d=(select COUNT(ssex) from tb where ssex=1)
,@e=(select COUNT(ssex) from tb where ssex=0)
,@f=(select COUNT(birthday) from tb where year(birthday)=1989)
,@h=(select COUNT(birthday) from tb where year(birthday)=1990)
,@g=(select COUNT(birthday) from tb where year(birthday)=1991)
end
select * from tb