sql_case when_根據不同使用者型別統計收藏記錄數

wisdomone1發表於2010-07-20
Select x.usertype,count(x.favorityid) from
(
Select
Case When A.Usertype=B.Loginid Then B.Nickname
     When A.Usertype=C.Loginid Then C.Nickname
     When A.Usertype=D.Loginid  Then D.Nickname
End As usertype,a.favorityid
From O_Classfavorityinfo A,E_Logininfo B,e_parentlogininfo C,E_Teacherlogininfo D
Where A.Usertype=B.Loginid Or A.Usertype=C.Loginid Or A.Usertype=D.Loginid
) x
group by x.usertype

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-668497/,如需轉載,請註明出處,否則將追究法律責任。

相關文章