17 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
select Table1.A, temp_table1.Expr1 from (
SELECT A, row_number() over (ORDER BY A) AS Expr1
FROM (SELECT DISTINCT A
FROM Table1
) AS derivedtbl_1 ) temp_table1 join Table1
on temp_table1.A=Table1.A
白猪掌柜的
TA贡献1893条经验 获得超10个赞
select * from (select row_number() over (order by A) as Num,* from tableName) as tt
繁花不似锦
TA贡献1851条经验 获得超4个赞
select a.A,b.Num from Tb a inner join (select row_number() over (order by A) as Num,A from tb group by A) as b on a.A = b.A
智慧大石
TA贡献1946条经验 获得超3个赞
算了我已经在后台给处理了
dt.Columns.Add("SUP_ASSESS_ORDER_NO", typeof(int));
int tmpInt = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
dt.Rows[i]["SUP_ASSESS_ORDER_NO"] = tmpInt;//默认第一行给1
}
else
{
if (dt.Rows[i]["SUP_ASSESS_ORDER_NO"].ToString() != dt.Rows[i - 1]["SUP_ASSESS_ORDER_NO"].ToString())//当前一行与上一行的比较,如果不等,则 +1
{
tmpInt++;
}
dt.Rows[i]["SUP_ASSESS_ORDER_NO"] = tmpInt;
}
}
dt.Columns.Add("SUP_ASSESS_ORDER_NO", typeof(int));
int tmpInt = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i == 0)
{
dt.Rows[i]["SUP_ASSESS_ORDER_NO"] = tmpInt;//默认第一行给1
}
else
{
if (dt.Rows[i]["SUP_ASSESS_ORDER_NO"].ToString() != dt.Rows[i - 1]["SUP_ASSESS_ORDER_NO"].ToString())//当前一行与上一行的比较,如果不等,则 +1
{
tmpInt++;
}
dt.Rows[i]["SUP_ASSESS_ORDER_NO"] = tmpInt;
}
}
达令说
TA贡献1821条经验 获得超6个赞
用一个简单的dense_Rank()函数即可
------分组显示示例
IF NOT OBJECT_ID('[XXX]') IS NULL
DROP TABLE [XXX]
GO
CREATE TABLE [XXX](
[TID] int)
go
INSERT [XXX]
SELECT 1 UNION ALL
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 4
GO
----select * from XXX
/*
TID
1
1
2
4
*/
select TID,(dense_Rank() over (order by TID asc)) as num
from xxx
/*
TID num
1 1
1 1
2 2
4 3
*/
开心每一天1111
TA贡献1836条经验 获得超13个赞
这是我查询的语句,有点雷人
select row_number() over(order by Month_Rating desc) as 'Row_Id',*
from (select distinct a.SUP_MANAGE_ID,b.SUP_NAME,(select CAST(SUM(SUP_ASSESS_POINT)/COUNT(0) as numeric(5,2))
from ASSESS_SUP_CLOSE_POINT where SUP_MANAGE_ID=a.SUP_MANAGE_ID and ORGANISE_ID='YFJC00' and YEAR_MONTH_STR between '201001' and '201003') as 'Month_Rating'
from ASSESS_SUP_CLOSE_POINT a inner join SUP_INFO b on a.SUP_MANAGE_ID=b.SUP_MANAGE_ID where ORGANISE_ID='YFJC00' and YEAR_MONTH_STR between '201001' and '201003') a
select row_number() over(order by Month_Rating desc) as 'Row_Id',*
from (select distinct a.SUP_MANAGE_ID,b.SUP_NAME,(select CAST(SUM(SUP_ASSESS_POINT)/COUNT(0) as numeric(5,2))
from ASSESS_SUP_CLOSE_POINT where SUP_MANAGE_ID=a.SUP_MANAGE_ID and ORGANISE_ID='YFJC00' and YEAR_MONTH_STR between '201001' and '201003') as 'Month_Rating'
from ASSESS_SUP_CLOSE_POINT a inner join SUP_INFO b on a.SUP_MANAGE_ID=b.SUP_MANAGE_ID where ORGANISE_ID='YFJC00' and YEAR_MONTH_STR between '201001' and '201003') a
- 17 回答
- 0 关注
- 534 浏览
添加回答
举报
0/150
提交
取消