selet top 5 id,name from table where id=1我想这样做,如果数据表里的id=1的记录小于5条,就显示id等于其它值的!~~要排序应该怎样做呢??例如:table里,id=1的只有一条记录,我想把这条记录放到最前,再显示其它id,按排序显示够5条....不知说得清不清楚...
set rowcount 5 select id, name from tbName where id=1 union all select id, name from tbName where id<>1 set rowcount 0
如果ID=1是最小值SELECT TOP 5 id,name from [table] order by id 如果ID=1不是最小值SELECT TOP 5 id,name FROM (SELECT 1 AS N,id,name from [table] WHERE ID=1 UNION ALL SELECT 2 AS N,id,name from [table] where id<>1) A ORDER BY N
id=1的只有一条记录,我想把这条记录放到最前,再显示其它id其他的id随便??selet top 5 id,name from table order by case id when 1 then 0 else 1 end
其它id,按排序啊...id=1的有可能一条记录都没有的...
selet top 5 id,name from table where id>=1 order by id
set rowcount 5 select id, name from tbName where id=1 union all select id, name from tbName where id<>1 group by [日期字段] set rowcount 0
不太理解,和尚的简单做法: selet top 5 id,name from table where id>=1 order by id不是你想要的吗?
select id, name from tbName where id=1
union all
select id, name from tbName where id<>1
set rowcount 0
SELECT 2 AS N,id,name from [table] where id<>1) A
ORDER BY N
order by case id when 1 then 0 else 1 end
selet top 5 id,name from table
where id>=1
order by id
select id, name from tbName where id=1
union all
select id, name from tbName where id<>1 group by [日期字段]
set rowcount 0
selet top 5 id,name from table
where id>=1
order by id不是你想要的吗?