Sql server 2008 从2个表中选择并获得表2的1个结果

Sql server 2008 从2个表中选择并获得表2的1个结果,sql-server-2008,Sql Server 2008,我有2个表,表2包含了许多商店的地址。表2按车间ID与表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 请

我有2个表,表2包含了许多商店的地址。表2按车间ID与表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

请参见

谢谢您的回答,问题已解决:)),非常感谢:)但(分区)上的行号()无法转换为linq,linq不支持行号()(
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