两个表相关联数据,同一个ID号,有可能查出来一条或多个记录,希望重新生成一列,如果是1个就赋值1,如果多行,就以ID顺序生成1,2,3……
select a.aaid,b.bbid,b.bbvalue,row_number()over(partition by a.aaid order by b.bbvalue) sortno from AA a
left join BB b on a.aaID=b.bbID
这个直接帆软报表直接解决
参考序号-https://help.fanruan.com/finereport/doc-view-342.html
sqlserver?
SELECT ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID ASC) [I] ,* FROM (
SELECT A.ID,B.AA,B.CCC FROM TABLEA A INNER JOIN TABLEB B ON A.ID=B.ID
) T
组内序号