有一个TSQL视图,我需要按一列分组,但是,我正在使用nhibernate(C#),我也需要指定Id列..我的查询看起来像:
SELECT
row_number() over(order by id)as Id,
column_name,..etc
from tblName
group by column_name
这给了我一个错误,即Id必须包含在group by子句中。
或者,我可以写:
SELECT
row_number() over(order by id)as Id,
column_name,..etc
from tblName
group by column_name, id
返回相同column_name名称的多行。
有解决方法吗?
答案 0 :(得分:1)
我想你想这样做:
Select row_number() over(order by column_name) as ID, column_name from (
Select distinct column_name from tblName
) as A
答案 1 :(得分:0)
你是说这个吗?
SELECT
row_number() over(partition by column_name order by id)as Id,
column_name,..etc
from tblName