菜鸟2问,大家帮忙(1)
1.
(1)我有一个表1
ID NAME
1 JIM
2 DAVID
(2)我有表2
LID ID LANGUAGE
1 1 JAVA
2 1 .NET
3 2 JAVA
4 2 VB
我想在GRIDVIEW中这样显示
ID NAME JAVA .NET VB
1 JIM 1 1 0
2 DAVID 1 0 1
求解决方案
------解决方案--------------------select distinct(b.id) ID,a.name NAME,SUM(case when b.language=JAVA then 1 else 0 end) as JAVA,SUM(case when b.language=.NET then 1 else 0 end) as .NET,SUM(case when b.language=VB then 1 else 0 end) as VB
FROM 表1 a left join 表2 b on a.id=b.id
------解决方案--------------------帮顶
------解决方案--------------------up
------解决方案--------------------用临时表
------解决方案--------------------select distinct(b.id) as id,a.name as name,
sum(case when b.language= 'java ' then 1 else 0 end) as java,
sum(case when b.language= 'vb ' then 1 else 0 end) as vb,
sum(case when b.language= '.net ' then 1 else 0 end) as net
FROM 表1 a left join 表2 b on a.id=b.id group by a.name ,b.id
上面都是错的.