我从另一篇文章中获得了这段代码:
SELECT bar
FROM (SELECT S.subcategoryname As bar,
C.CategoryName AS SortName,
ROW_NUMBER() OVER (PARTITION BY C.CategoryName
ORDER BY subcategoryname) As RowNum
FROM category C
LEFT JOIN subCategory S ON C.CategoryID = S.CategoryID
UNION ALL
SELECT C.CategoryName As bar,
C.CategoryName AS SortName,
0
FROM category C) foo
ORDER BY foo.SortName, RowNum
它有效,但我怎样才能检索到不仅仅是categoryName
和subCategoryName
. 有没有办法从所有列中检索数据?
我的代码:
select * from (select s.titlu_subcerinta as bar,c.titlu_Cerinta As SortName, ROW_NUMBER() over(partition by c.titlu_Cerinta order by titlu_subcerinta) as RowNum
from cerinteProiect c left join subcerinteProiect s on c.id_cerinta = s.id_cerinta
UNION ALL
select c.titlu_Cerinta As bar, c.titlu_Cerinta As SortName,0
from cerinteProiect c
)
foo
order by
foo.SortName,RowNum