【问题标题】:sql group by with inner join [duplicate]带有内部连接的sql group by [重复]
【发布时间】:2018-01-19 15:49:45
【问题描述】:

我想按此查询的结果进行分组,如下所示。

select takes.namestudent, takes.pointscourse    
from takes    
inner join follows    
on follows.idstudent = takes.idstudent    
where follows.completedprogram = 'yes'

结果:

'Dan Purple',4
'Dan Purple',2
'Dan Purple',3
'Dan Purple',2
'Dan Purple',2
'Bob White',2
'Bob White',4
'Bob White',3
'Bob White',3
'Bob White',2

但我想要这样:

'Dan Purple', 13
'Bob White', 14

我尝试了几种分组或求和的可能性,但我无法做到正确。 我做错了什么?

【问题讨论】:

  • 请通过GROUP BY 发布您的最佳尝试。那么我们就可以回答您的问题了。

标签: sql


【解决方案1】:
select takes.namestudent, sum(takes.pointscourse) as total
from takes 
inner join follows on follows.idstudent = takes.idstudent 
where follows.completedprogram = 'yes'
group by takes.namestudent

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 2013-01-08
    • 2013-01-03
    • 2012-04-22
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 2021-02-14
    • 2011-12-05
    相关资源
    最近更新 更多