解决方案 »
- 函数里面能实现动态读取表里面的任何列的数据么?
- sql查询更新问题。急在线。。。
- 一个应用程序的WEB安装过程,求解
- 随机抽取数据
- 多表查询中的排除列查询方法
- 请教:如何替换一个字段的一部分内容
- alter table ActiveSubscriptions with nocheck add CONSTRAINT [FK_ActiveSubscriptions_Subscriptions] foreign key ([SubscriptionId]
- 请教一个有关sqlserver7。0连接问题?
- 真需要重新安装sql server吗?
- 统计迟到合计???
- Server2008经常数据库连接超时,电脑重启几次可能会恢复正常。select没事,update,insert和delete就会一直无法执行
- 高分求一句有难度的SQL语句
go
create table #t
(
lrry varchar(2),
jyry varchar(2)
)
go
insert #t
select 'a','b' union all
select 'a','b' union all
select 'a','b'
go;with t
as(
select lrry as ry,* from #t
union all
select jyry,* from #t
)
select ry,
SUM(case when ry=lrry then 1 else 0 end) as lrry,
SUM(case when ry=jyry then 1 else 0 end) as jyry
from t group by ry
/*
ry lrry jyry
--------------------------
a 3 0
b 0 3
*/
drop table #t
(select 'a','b'
union all select 'a','b'
union all select 'a','b'
)
select lrry=(select count(*) from cte t where t.lrry=a.name),jyry=(select count(*) from cte t where t.jyry=a.name),name
from (select distinct lrry as name from cte
union all select distinct jyry from cte
)a/*
lrry jyry name
3 0 a
0 3 b
*/