1. 在第一列显示行数
2. 如记录不满 N 条(假设N=5), 要补齐记录, 全部为空即可例: select ......字段1 字段2
1 aaa
2 bbb
3 ccc
4 null
5 null
....谢谢!
2. 如记录不满 N 条(假设N=5), 要补齐记录, 全部为空即可例: select ......字段1 字段2
1 aaa
2 bbb
3 ccc
4 null
5 null
....谢谢!
select @b=COUNT(*) from tb
set @n=5
if(@b<=@n)
begin
insert into tb values (@b+1,NULL)
set @b=@b+1
end
select * from table
------------------------
name deptid
张三 01
李四 02
王五 03
赵六 04
周七 05
想要的结果,假设只要五条:
select ????
------------------------
id name deptid
1 李四 02
2 王五 03
3 赵六 04
4 null null
5 null null
....PS: 不用null,用空字符也行
select count(0)as sumcase sum>=5 then select top 5...else select *from.. union selet "".""...
select @b=COUNT(*) from tb
set @n=5
if(@b<=@n)
begin
insert into tb values (@b+1,'')
set @b=@b+1
end
select @b=COUNT(*) from tb
set @n=5
if(@b<=@n)
begin
insert into tb values (@b+1,'')
set @b=@b+1
end
--insert into abc values('1','a')
--insert into abc values('2','b')
--insert into abc values('3','c')
--insert into abc values('4','d')
--insert into abc values('5','e')
select a.aid,b.aname
from
abc a,
(
select * from abc where aid in('1','2')--where后面加条件
) as b
where a.aid*=b.aid
结果:
aid aname
---------- --------------------
1 a
2 b
3 NULL
4 NULL
5 NULL(5 行受影响)