Traditional Culture Encyclopedia - Hotel reservation - Ask a difficult sql query and try your database writing level.
Ask a difficult sql query and try your database writing level.
Select the maximum (hotel price), minimum (hotel price), count (room price) and * from the hotel prices.
Inner join Hotel on hotle.hotelname = hotelprice.hotelname.
Inner join Hotel on Hotelpic. HotelName = HotelPrice. HotelName
The house price is between 200 and 300.
Group by hotel. Hotel name
For the record, the above sentence is just wrapped for better looking.
Using the principle of grouping query, we can group hotels by name, so that we can classify hotels by name and find out the highest price and the lowest price in each hotel between 200 and 300.
Not tested, but the principle must be correct.
Maximum value, minimum value, count, join query and grouping query are all used.
Reasons for using grouped queries:
Maximum \ minimum \ count, etc. Is an aggregate function, which should be displayed together with other information and classified by hotel. Only group queries can be used.
But personally, the design of three tables in this database is problematic.
First of all, these three tables can only be connected by the hotel name. The id should be the identity column and the primary key, so that the three tables cannot establish the relationship between the primary key and the foreign key.
Secondly, if there is no master-foreign key relationship, how to ensure that a picture information of a hotel is added, and the hotel information also has master table data, so that this data will be redundant in the future.
In addition, the hotel prices, pictures and other information you want to count should use non-empty constraints. Otherwise, the statistics will go wrong.
Finally. You don't need to write SQL in one sentence, you can write it in multiple sentences, or you can do it through views, temporary tables, etc. Multi-statement SQL can be called by stored procedures. And the efficiency is higher than that of single sentence direct calling. (No multiple queries or temporary tables)
- Related articles
- How to return coupons to Chengdu Red Star Restaurant?
- How about Chongqing Youyu Construction Engineering Co., Ltd.?
- How much discount can you give for long-term hotel rental?
- What stations does the k2285 train pass by?
- Why are travel disappointments always greater than expectations?
- What brand is the watch that Sheng Zhenning gave Xia Qian?
- What is the telephone number of Zhejiang Pudding Hotel Co., Ltd.?
- I want to ask which TV series is Sheng Di Hotel?
- Who knows where the Guangzhou leather goods wholesale market is?
- Can soap be taken on the plane?