SQL質疑応答スレ 18問目

35NAME IS NULL2018/02/04(日) 17:18:13.30ID:???
>>33
SQL-Server なら
select T.ID as ID, T.NAME as NAME, T.ID2 as ID2, T.DATA as DATA
from (
select
row_number() over (
partition by TableA.Id
order by
case TableB.[KEY]
when 2 then 0 else 1
end,
TableB.[KEY] asc
) as R,
TableA.ID as ID,
TableA.NAME as NAME,
TableB.ID2 as ID2,
TableB.DATA as DATA
from TableA left join TableB on TableA.ID = TableB.ID
) T
where T.R = 1

新着レスの表示
レスを投稿する