blog.csdn.net比较烦的地方...:(


您看到这个页面
肯定是什么地方出错了
人难免会犯错
机器亦然
如果您没有搞错地址
多半是现在系统太忙
稍等片刻再试试

晕阿,看一次晕一次...

阅读更多
换一批

看着比较烦的SQL

03-06

[code=SQL]rncreate table #u(uid int,sum1 int,sum2 int)rninsert into #u values (1,2,3)rninsert into #u values (2,1,0)rninsert into #u values (3,0,0)rninsert into #u values (4,1,2)rninsert into #u values (5,0,0)rninsert into #u values (6,0,0)rninsert into #u values (7,0,0)rnrncreate table #m(mid int,uid int,tid int,ind int)rninsert into #m values (1,1,11,0)rninsert into #m values (2,1,11,1)rninsert into #m values (3,1,11,1)rninsert into #m values (4,4,12,0)rninsert into #m values (5,4,12,1)rninsert into #m values (6,4,12,1)rninsert into #m values (7,1,12,1)rninsert into #m values (8,1,13,0)rninsert into #m values (9,2,14,0)rnrncreate table #s(mid int)rninsert into #s values (10)rninsert into #s values (11)rnrncreate table #t(tid int,mid int)rninsert into #t values (11,10)rninsert into #t values (12,10)rninsert into #t values (13,10)rninsert into #t values (14,11)rnrnrnSELECT * FROM #u;rnSELECT * FROM #m;rnSELECT * FROM #s;rnSELECT * FROM #t;rnrnSELECT count(case ind when 0 then 0 end) as sum1,count(case ind when 1 then 1 end) as sum2, uid FROM #m group by uid;rnrndrop table #u,#m,#s,#t;rnrnrn/* rnuid sum1 sum2rn----------- ----------- -----------rn1 2 3rn2 1 0rn3 0 0rn4 1 2rn5 0 0rn6 0 0rn7 0 0rnrn(7 行受影响)rnrnmid uid tid indrn----------- ----------- ----------- -----------rn1 1 11 0rn2 1 11 1rn3 1 11 1rn4 4 12 0rn5 4 12 1rn6 4 12 1rn7 1 12 1rn8 1 13 0rn9 2 14 0rnrn(9 行受影响)rnrnmidrn-----------rn10rn11rnrn(2 行受影响)rnrntid midrn----------- -----------rn11 10rn12 10rn13 10rn14 11rnrn(4 行受影响)rnrnsum1 sum2 uidrn----------- ----------- -----------rn2 3 1rn1 0 2rn1 2 4rnrn(3 行受影响)rnrn*/rn[/code]rnrn要求执行“Delete From [#s] Where mid = 10后rnrn[code=SQL]rnrn/*rn(1 行受影响)rnuid sum1 sum2rn----------- ----------- -----------rn1 0 0rn2 1 0rn3 0 0rn4 0 0rn5 0 0rn6 0 0rn7 0 0rnrn(7 行受影响)rnrnmid uid tid indrn----------- ----------- ----------- -----------rn9 2 14 0rnrn(1 行受影响)rnrnmidrn-----------rn11rnrn(1 行受影响)rnrntid midrn----------- -----------rn14 11rnrn(1 行受影响)rnrnsum1 sum2 uidrn----------- ----------- -----------rn1 0 2rnrn(1 行受影响)rn*/rn[/code]

没有更多推荐了,返回首页