# 超难复杂查询如何写？

0
[已解决问题] 解决于 2011-04-09 13:32

bianhao    chicun    didian
1           17        gz
2           15        gz
3           17        sh
4           19        bj
5           19        sh
6           17        bj
7           17        bj

chicun    gz   sh   bj
15        1    0     0
17        1    1     2
19        0    1     1

xzf_fancy | 初学一级 | 园豆：28

0

`USE TEMPDBGOCreate Table #temp(bianhao int Primary Key Identity(1,1) not null, chicun int,didian nvarchar(5))GOINSERT INTO #tempSelect 17,'gz' UnionSelect 15,'gz' UnionSelect 17,'sh' UnionSelect 19,'bj' UnionSelect 19,'sh' UnionSelect 17,'bj' UnionSelect 17,'bj' GOINSERT INTO #temp Values(17,'bj')SELECT * from #tempSelect chicun,MAX(isnull(gz,0)) as gz,MAX(isnull(bj,0)) as bj,MAX(isnull(sh,0)) as sh From(Select chicun,Case didian when 'gz' then Count(chicun) end as gz,Case didian when 'bj' then Count(chicun) end as bj,Case didian when 'sh' then Count(chicun) end as shFrom #tempGroup By chicun,didian) as a Group By chicun`

0

您需要登录以后才能回答，未注册用户请先注册