mysql - SQL Longest Stay -


hi ask problem got.i got database of hotel , find costumer longest stay.

i got 3 tables:

  1. costumer (code_costumer,name,surname),
  2. stay (code_stay,date_start,date_end),
  3. costumer_stay (code_stay,code_costumer)

the script created:

select datediff(date_end,date_start) dd,        stay.code_stay,costumer_stay.code_costumer stay inner join costumer_stay            on stay.code_stay=costumer_stay.code_stay; 

but cant 1 person longest stay,i that:

id|code_stay|code_costumer| --------------------------- 25|xa21     |1001         | 8 |xb24     |1005         | 7 |xb30     |1003         | 

select datediff(date_end,date_start) dd,        stay.code_stay,costumer_stay.code_costumer stay  inner join costumer_stay on stay.code_stay = costumer_stay.code_stay order dd desc limit 1 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -