EfrainSQL
EfrainSQL

Reputation: 3

SELECT MAX for multiple

I'd like to find the userid and max transcript record for two (or more) classes in one query but i am only getting one max record for the two, i.e. if i user took both classes i'm on only getting the max record for the last class he took, not the max record of both classes.

i'd like to get the max record for both classes. This is what i've got:

select userid, max(transcriptid)
from chris_dwh.ekp_transcript_v t
where t.learningid in ('EKP000000708', 'EKP000000523')

my result is one userid and one transcriptid when i'd like to see something like

userA    EKP009037723
userA    EKP009036301
userB    EKP009057809
userB    EKP008479198

Upvotes: 0

Views: 49

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269973

Do you just want to add learningid to your group by?

select t.userid, max(t.transcriptid)
from chris_dwh.ekp_transcript_v t
where t.learningid in ('EKP000000708', 'EKP000000523')
group by t.userid, t.learningid;

Upvotes: 1

Related Questions