oracle - Which hotel has the most stayings? -


i pretty new @ oracle, , doing examples found on 1 of websites learn new. 1 of tasks tables, hotel has stayings. find 1 problem realy complex , can not solve myself, happy if me soultion , explanation why is way.

i understood question in way, have connect visitor, visited, hotel, owning , owner tables.

to explain. owning table connecting owners hotels , visited table connecting visitors hotel in stayed.

this tables example: pastebin link example.

what have tried far is:

select visitor.id, visitor.name, visitor.surname, hotel.name visitor left join visiting on visitor.id = visiting.tk_visitor left join hotel on hotel.id = visiting.tk_hotel order hotel.id asc; 

this connecting 3 tables, visitors , hotels connected in 1 table, can't go further.

i hope able me, can learn new on example.

thanks in addition!

which hotel has stayings[?]

each visit corresponds 1 row in table visited, therefore want count rows of visited on per-hotel basis. that's this:

select tk_hotel, count(*) visits visited group tk_hotel 

if want 1 (one of ones) visits can order results visit count, , take first. name of hotel instead of id, should join previous result hotel table:

select h.name, mv.visits (     select tk_hotel, count(*) visits     visited     group tk_hotel     order count(*) desc   ) mv   join hotel h on h.id = mv.tk_hotel rownum = 1 ; 

update

if instead want all rows having maximum number of visits, that's different kettle of fish. here's way express it:

with visit_count (   select tk_hotel, count(*) visits   visited   group tk_hotel ) select h.name, vc.visits   hotel h   join visit_count vc on h.id = vc.tk_hotel vc.visits = (select max(visits) visit_count) 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -