tableA
id name
10 天在
11 在有
12 中有
....
查询它,如 select * from tableA希望出现
xxx id name
1 10 天在
2 11 在有
3 12 中有
....
xxx 字段自动以结果的行数为值不希望在程序中实现,而直接使用sql语句
id name
10 天在
11 在有
12 中有
....
查询它,如 select * from tableA希望出现
xxx id name
1 10 天在
2 11 在有
3 12 中有
....
xxx 字段自动以结果的行数为值不希望在程序中实现,而直接使用sql语句
要求是SQL2005的版本以上才行,否则不可以。
只能采用插入临时表或表变量的方式,然后再进行查询才可以。
declare @tableA table(id int, name char(10))
insert @tablea
select 11, '在有' union all
select 10, '天在' union all
select 12, '中有' --查询SQL
select (select count(1) from @tablea t where t.id <= a.id) as xxx, id, name
from @tablea a order by xxx
/*
xxx id name
----------- ----------- ----------
1 10 天在
2 11 在有
3 12 中有
*/
FROM userList INNER JOIN
shopList ON userList.userid = shopList.shopid
WHERE (shopList.shopName LIKE '%公司%') OR
EXISTS
(SELECT 1 AS Expr1
FROM keyAdList
WHERE (adKey = '家具') AND (shopid = userList.userid))
ORDER BY
(SELECT TOP (1) money
FROM keyAdList
WHERE (adKey = '家具') AND (shopid = userList.userid)
ORDER BY money DESC) DESC, userList.userid DESC像这个语句的分页操作
select * from #s这样应该可以