[英]Combine 2 Mysql queries into one
i have two queries我有两个疑问
1) 1)
SELECT COUNT(room_id) FROM room WHERE hotel_id LIKE '777' GROUP BY room_id
2) 2)
SELECT COUNT(room_id) FROM orders WHERE hotel_id LIKE '777' AND checkout = '$today'
I want to know, if i can create a single query which will return both value.我想知道,是否可以创建一个将返回两个值的查询。 I tried JOIN but, can not get a wanted result.我试过JOIN但是,不能得到想要的结果。 (Do not know about JOIN s) (不知道JOIN )
I suspect the query you want is:我怀疑你想要的查询是:
SELECT COUNT(*) as NumRooms, SUM(checkout = '$today') as NumCheckoutToday
FROM orders
WHERE hotel_id LIKE '777' ;
Your first query is going to return a list of "1"s for every room in the hotel.您的第一个查询将返回酒店中每个房间的“1”列表。 That doesn't seem particularly useful.这似乎不是特别有用。 I'm guessing you want the actual count.我猜你想要实际计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.