超难的SQL语句,该怎样写? select id,(select count(1) from ta where layer > a.layer) as layer from ta a 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 declare @t table(ID int,Layer int)insert @t select 1,3 union select 2,5 union select 3,6 union select 4,8 union select 5,10 union select 6,1select id,(select count(1) from @t where layer > a.layer) as layer from @t a/*id layer ----------- ----------- 1 42 33 24 15 06 5*/ select a1.ID,isnull(count(a2.*),0) as Layerfrom A a1 left join A a2on a1.Layer>a2.Layer select a1.ID,isnull(count(a2.ID),0) as Layerfrom @t a1 left join @t a2on a1.Layer<a2.Layergroup by a1.IDorder by a1.ID 这个问题我不会,SO大家来指点下看看哦~ 多表查询问题 简单问题 哪位可以给俺份存储过程的教程学习学习,谢谢啊! 高手们帮帮忙! 问一个弱弱的问题,关于UPDATE 查询一个表内不重复的而且是最后日期的 存储语句 寻求一个SQL解决方案 这个问题已经耗费了我3天了!拯救我吧!! SQL where 条件书写的难题? 查询语句,帮忙
insert @t
select 1,3 union
select 2,5 union
select 3,6 union
select 4,8 union
select 5,10 union
select 6,1
select id,(select count(1) from @t where layer > a.layer) as layer from @t a/*id layer
----------- -----------
1 4
2 3
3 2
4 1
5 0
6 5
*/
a1.ID,isnull(count(a2.*),0) as Layer
from
A a1
left join
A a2
on
a1.Layer>a2.Layer
a1.ID,isnull(count(a2.ID),0) as Layer
from
@t a1
left join
@t a2
on
a1.Layer<a2.Layer
group by
a1.ID
order by
a1.ID