0
我有2個表,表2包含很多商店的地址。表2由Shop_ID 參考表1我想選擇那樣[請參閱圖片] 請幫助我!從2個表中選擇並得到1個表的結果2
我有2個表,表2包含很多商店的地址。表2由Shop_ID 參考表1我想選擇那樣[請參閱圖片] 請幫助我!從2個表中選擇並得到1個表的結果2
你可以使用row_number()
:
select shop_id,
shop_name,
shop_address
from
(
select t1.shop_id,
t1.shop_name,
t2.shop_address,
row_number() over(partition by t1.shop_id
order by t1.shop_name, t2.shop_address) rn
from table_1 t1
inner join table_2 t2
on t1.shop_id = t2.shop_id
) src
where rn = 1
您還可以使用聚合函數:
select t1.shop_id,
t1.shop_name,
max(t2.shop_address) shop_address
from Table1 t1
inner join table2 t2
on t1.shop_id = t2.shop_id
group by t1.shop_id, t1.shop_name
感謝您的回答,問題已解決:)),非常感謝:) – hackchick
歡迎您幫助 – Taryn
但row_number()over(分區)無法轉換爲linq,linq不支持row_number() :( – hackchick