我在执行查询时得到了结果:
state city user_count restaurant_count order_count
a b 0 0 5
a c 2 0 0
a d 0 0 0
我的查询是:
SELECT `eat_state_locale`.`state`, `eat_city_locale`.`city`, `eat_city_locale`.`location`, `eat_city`.`city_id`, count(distinct eat_user.user_id) as user_count, count(distinct eat_delivery.restaurant_id) as restaurant_count, count(distinct eat_order.order_id) as order_count FROM (`eat_state`) JOIN `eat_state_locale` ON `eat_state_locale`.`state_id`=`eat_state`.`state_id` JOIN `eat_city` ON `eat_state`.`state_id`=`eat_city`.`state_id` JOIN `eat_city_locale` ON `eat_city_locale`.`city_id`=`eat_city`.`city_id` LEFT JOIN `eat_user` ON `eat_user`.`city_id`=`eat_city`.`city_id` LEFT JOIN `eat_delivery` ON `eat_delivery`.`delivery_city_id`=`eat_city`.`city_id` LEFT JOIN `eat_order` ON `eat_order`.`delivery_city_id`=`eat_city`.`city_id` LEFT JOIN `eat_printer` ON `eat_printer`.`order_id`=`eat_order`.`order_id` WHERE `eat_state_locale`.`language_id` = 1 AND `eat_city_locale`.`language_id` = 1 GROUP BY `eat_city`.`city_id` ORDER BY `eat_state`.`state_id` asc
这里我需要获得结果(在避免空值之后:)
state city user_count restaurant_count order_count
a b 0 0 5
a c 2 0 0
我将如何得到这样的结果?这里的计数结果没有问题。我需要避免空结果
答案 0 :(得分:1)
修改强>
SELECT
blah
HAVING
user_count > 0 AND
restaurant_count > 0
AND order_count > 0;
答案 1 :(得分:0)
WHERE .... AND ( user_count != 0 OR restaurant_count != 0 OR order_count != 0 )
如果不起作用,请尝试:
GROUP BY .... HAVING user_count > 0 OR restaurant_count > 0 OR order_count > 0
答案 2 :(得分:-1)
尝试在哪里条件
AND your_field IS NOT NULL