数据表1: id name dd cc ss zz
0001 admin de df dg
0002 guest ae af ag ds
0003 manager dd dd dd dd
0004 boss da sa sa df想要达到的要求:以zz字段为依据,把数据表1中的记录整合成二条,一条是zz为空的,另一条是zz字段不为空的希望达到的最终结果:
zz 字段名
记录一为空
ds 记录二不为空(数据可以是以前任一记录中的)
0001 admin de df dg
0002 guest ae af ag ds
0003 manager dd dd dd dd
0004 boss da sa sa df想要达到的要求:以zz字段为依据,把数据表1中的记录整合成二条,一条是zz为空的,另一条是zz字段不为空的希望达到的最终结果:
zz 字段名
记录一为空
ds 记录二不为空(数据可以是以前任一记录中的)
union
select top 1 * from 数据表1 where zz is not null
=================================
还是用top,只不过在order by的后面加上desc(降序排列)
如果要取中間一條,那還要看相關的約束條件才能取得。
//或者是最后面的那一条,第一条用TOP,那最后一条呢?用什么,
select * from 数据表1 where zz is null
union
select top 1 * from 数据表1 where zz is not null order by 1 desc