Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
lukael82
Starting Member
5 Posts |
Posted - 2013-12-03 : 16:31:39
|
Hello, I hope this is right forum to ask question. My problem is probably not so hard, but I can't resolve it - I'm a beginner in SQL.I have 3 tables, first is:REŽISERŠIFRA_REŽISERJA | PRIIMEK_REŽISERJA1...................... | ALLEN2...................... | HITCHCOCK3, etc................ | KUBRICK, etc.FILMŠIFRA_FILMA | ŠIFRA_REŽISERJA1................ | 12................ | 53, etc.......... | 5, etc. KASETAŠIFRA_FILMA | ŠTEVILO_IZPOSOJ1................ | 42................ | 13, etc.......... | 2, etcThese three tables represent database of movies, their producing directors, and borrowed video-tape of their movies.QUESTION : I need to create code, where I must show result of ŠIFRA_IGRALCA,PRIIMEK_IGRALCA and the sum of ŠTEVILO_IZPOSOJ where ŠIFRA_REŽISERJA is in ŠIFRA_FILMA, in DESC order.MY CODE SO FAR :select režiser.šifra_režiserja, režiser.priimek_režiserja, kaseta.število_izposojfrom REŽISER , FILM, KASETAwhere REŽISER.ŠIFRA_REŽISERJA = FILM.ŠIFRA_REŽISERJA and FILM.ŠIFRA_FILMA = KASETA.ŠIFRA_FILMA group by režiser.šifra_režiserja, režiser.priimek_režiserja, kaseta.število_izposojhaving ??????????????????order by ŠTEVILO_IZPOSOJ desc;As you see, I have joined tables but no calculations, problem lies in third table KASETA, where I need to calculate "distinct" ŠIFRA_REŽISERJA from ŠIFRA_FILMA, and give that value a SUM of ŠTEVILO_IZPOSOJ. I think I can resolve this in Having clause, but I don't know how Hope that language isn't a problem, but for better understanding - all "ŠIFRA" names are basically "ID_NUMBER"Thanks for all your help,regards, Luka |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-12-03 : 16:58:40
|
[code]select r.šifra_režiserja , r.priimek_režiserja , sum(k.število_izposoj) as Total_število_izposojfrom REŽISER rinner join FILM f on f.ŠIFRA_REŽISERJA = r.ŠIFRA_REŽISERJAinner join KASETA k on k.ŠIFRA_FILMA = f.ŠIFRA_FILMAgroup by r.šifra_režiserja , r.priimek_režiserjaorder by sum(k.število_izposoj) desc;[/code]Be One with the OptimizerTG |
|
|
lukael82
Starting Member
5 Posts |
Posted - 2013-12-04 : 13:06:22
|
It works, perfectly !! Thanks TG, You're the man quote: Originally posted by TG
select r.šifra_režiserja , r.priimek_režiserja , sum(k.število_izposoj) as Total_število_izposojfrom REŽISER rinner join FILM f on f.ŠIFRA_REŽISERJA = r.ŠIFRA_REŽISERJAinner join KASETA k on k.ŠIFRA_FILMA = f.ŠIFRA_FILMAgroup by r.šifra_režiserja , r.priimek_režiserjaorder by sum(k.število_izposoj) desc; Be One with the OptimizerTG
|
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-12-04 : 13:10:50
|
Ha. Nope just a man.you're welcome.Be One with the OptimizerTG |
|
|
|
|
|
|
|