私は別の投稿からこのコードを持っています:
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