这个联表group by 语句应该怎么写?
tableA
Id Type1 TypeId Type3 Type4
1 类型8 11 1111 3
2 类型7 77 7878 98
3 类型2 20 111 76
4 类型8 11 78 78
tableC
TypeId Number
11 10
77 20
20 50
78 78
将tableA的TypeId字段和tableC的TypeId相关联,然后再对tableA的TypeId进行group by
我想要的效果是
Id Type1 TypeId Type3 Type4 Number
1 类型8 11 1111 3 10
4 类型8 11 78 78 78
2 类型7 77 7878 98 20
3 类型2 20 111 76 50
[最优解释]
纯粹你的例子的话,没必要用到groupby啊
SELECT a.id ,
a.type1 ,
A.typeid ,
a.type3 ,
a.type4 ,
C.number
FROM tableA a
INNER JOIN tableC c ON A.typeid = c.typeid
[其他解释]
如果 4 类型8 11 78 78 = 4 类型8 78 78 78
下面就是你要的结果
select a.Id,a.Type1,a.TypeId,a.Type3,a.Type4,c.Number from dbo.TableA as a inner join dbo.TableC as c on a.Typeid=c.TypeId
order by a.Type1 desc
[其他解释]
楼主的问题太屌丝了。