4
SELECT *
FROM `room_type`
WHERE h_id='$h_id'
  AND `rt_oc` >= '$tperson'
  AND `rt_num` <
    (SELECT COUNT(`check_out`)
     FROM `room_info`
     WHERE `h_id`='$h_id'
       AND
       LEFT JOIN `room_type` ON room_type.rt_type=room_info.room_type));

在这里,我想从 table1 中选择数据,它将比较 table2 的相同列值 sum 中的列值。

4

2 回答 2

0

您的查询应该是这样的:

SELECT *
FROM `room_type`
WHERE h_id='$h_id'
  AND `rt_oc` >= '$tperson'
  AND `rt_num` <
    (SELECT COUNT(`check_out`)
     FROM `room_info`
        LEFT JOIN `room_type` ON room_type.rt_type=room_info.room_type
           WHERE `h_id`='$h_id'));
于 2013-07-25T07:12:30.810 回答
0
WHERE `h_id`='$h_id'
       AND
       LEFT JOIN

这不起作用,需要像这样更新子查询:

(SELECT COUNT(`check_out`)
     FROM `room_info`
     LEFT JOIN `room_type` ON room_type.rt_type=room_info.room_type
     WHERE `h_id`='$h_id')

顺便说一句,您));在查询结束时进行了检查。

SELECT *
FROM `room_type`
WHERE h_id='$h_id'
  AND `rt_oc` >= '$tperson'
  AND `rt_num` <
    (SELECT COUNT(`check_out`)
     FROM `room_info`
     LEFT JOIN `room_type` ON room_type.rt_type=room_info.room_type
     WHERE `h_id`='$h_id')
于 2013-07-25T07:09:55.747 回答