我有以下由PHP脚本执行的SQL查询。问题是,即使不满足$nameValue
参数,它仍然会返回值。如何解决?我专门说:
WHERE ((driver_name = '$nameValue') AND
status = 'FEDEX' or status = 'UPS')
AND
仅在同时满足两个条件时返回,但仍显示状态为FEDEX
或UPS
$sql = "SELECT customer,
sum( status = 'FEDEX' ) as PickedUpNUM,
sum( status = 'UPS' ) as DeliveryNUM
from Equipment
WHERE ((driver_name = '$nameValue') AND
status = 'FEDEX' or status = 'UPS')
group by customer
Order by DeliveryNUM DESC";
答案 0 :(得分:1)
错误()位置
$sql = "SELECT customer,
sum( status = 'FEDEX' ) as PickedUpNUM,
sum( status = 'UPS' ) as DeliveryNUM
from Equipment
WHERE driver_name = '$nameValue' AND
(status = 'FEDEX' or status = 'UPS')
group by customer
Order by DeliveryNUM DESC";
答案 1 :(得分:0)
要使查询返回所需的结果,您需要进行一些更改
$sql = "SELECT customer,
sum( IF(status = 'FEDEX', 1, 0 ) as PickedUpNUM,
sum( IF(status = 'UPS', 1, 0 ) as DeliveryNUM
from Equipment
WHERE driver_name = '$nameValue' AND
(status = 'FEDEX' or status = 'UPS')
group by customer
Order by DeliveryNUM DESC";