我有一种情况,如果真执行另一个查询,我想比较两个查询的计数,否则返回null。这是到目前为止我所做的,问题出在第三部分,我不能选择多个列,因为我想获取所有字段或选定的字段。我也在phpmyadmin中尝试这个查询,并在标头中显示了整个查询,我不知道这是不是phpmyadmin特定的东西,或者我写的查询是错误的。
SELECT IF(
// this query count return 2
(select COUNT(*) as dailyBookingsCount FROM `cpd_booking` WHERE `isactive` = '1' AND `comp_id` = '57' AND `datetime` LIKE '%01-March-2019%')
<
// this query returns 100 from daily_bookings field
(SELECT daily_bookings FROM `cpd_company` WHERE comp_id = '57' AND status = '1'),
// here i want to select all columns
(SELECT comp_id FROM `cpd_company` WHERE comp_id = '57' AND status = '1'),
"null")