------解决方案-------------------- 如果是sqlserver,用case...when语句,对null值得记录去取上一个id对应的值
case eag when null then select eag where id=id-1(如果id是顺序加一的话)
或写个存储过程或者写代码逐条处理一下
------解决方案-------------------- group by isnull(x.eag,select eag from t where id=id-1) ------解决方案-------------------- group by isnull(eag,select eag from t where id=id-1) 他这里写的是指表; isnull(列名,取代值) ------解决方案-------------------- select t1.id, (select top 1 eag from tab where id < t1.id order by id desc)
from tab t1
where t1.eag is null
union all
select id, eag from tab where eag is not null
组合成上面的数据在分组
手打,错了,改改
如果在MSSQL中(select top 1 eag from tab where id < t1.id order by id desc) 不行
你就Left join ------解决方案--------------------
如果是sqlserver,用case...when语句,对null值得记录去取上一个id对应的值
case eag when null then select eag where id=id-1(如果id是顺序加一的话)
查找出来的全是空 这是为什么
select a.eag as 性别, count(1) as 数量
from (
select case
when t.eag is null then (select eag from test t1 where t1.id = t.id - 1) \
else t.eag end as eag
from test t
)a
group by a.eag;
------解决方案--------------------
select a.eag as 性别, count(1) as 数量
from (
select case
when t.eag is null then (select eag from test t1 where t1.id = t.id&nb