Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql连接查询,用于从两个表中选择一个表中有多行与第一个表匹配的行_Php_Mysql_Join - Fatal编程技术网

Php mysql连接查询,用于从两个表中选择一个表中有多行与第一个表匹配的行

Php mysql连接查询,用于从两个表中选择一个表中有多行与第一个表匹配的行,php,mysql,join,Php,Mysql,Join,为了在图像中获得结果,我现在使用这个查询 select h.*, group_concat(distinct room_type) as RoomTypes from hotel h left join rooms r on h.hotel_id = r.hotel_id group by h.hotel_id; 但是这个查询只返回文件中的房间类型。但我需要该表中的所有列 请在这方面帮助我。试着做些类似的事情。它假设可能有一个房间有wifi,但没有早餐和所有其他组合 SELECT h.*,

为了在图像中获得结果,我现在使用这个查询

select h.*, group_concat(distinct room_type) as RoomTypes
from hotel h 
left join rooms r on h.hotel_id = r.hotel_id
group by h.hotel_id;
但是这个查询只返回文件中的房间类型。但我需要该表中的所有列


请在这方面帮助我。

试着做些类似的事情。它假设可能有一个房间有wifi,但没有早餐和所有其他组合

SELECT h.*, SUM(r,availability) + ' rooms ' + 
            CASE WHEN r.wifi = 1 THEN ' with wifi ' ELSE '' END +
            CASE WHEN r.breakfast = 1 THEN ' with breakfast' ELSE '' END
            as RoomInfo
FROM hotel h 
LEFT JOIN rooms r ON h.hotel_id = r.hotel_id
GROUP BY h.hotel_id, r.room_type, r.wify, r.breakfast
HAVING SUM(r.availability) > 0;
前端需要处理好格式设置。

尝试执行sql

select h.*, CONCAT_WS(' ', r.availability, room_type, 'rooms', IF(r.wifi = 1 AND r.breakfast = 1,'with wifi and breakfast',IF(r.wifi = 1 ,'with wifi','with breakfast'))) AS Attributes
from hotels as h
inner join rooms as r on r.hotel_id = h.id
group by h.id, r.room_type, r.wifi, r.breakfast HAVING SUM(r.availability) > 0;