作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在点赞搜索中使用一个表的计数值。我能怎么做?这是我的查询,它显示 #1111 - 组函数的使用无效
select driver_details.DriverId,
count(taxi_trip.AutoId) AS TotalTrip,
sum(taxi_trip.TripDistance) AS TotalTripDistance,
sum(taxi_trip.TotalFare) AS TotalTripFare
from driver_details
left join taxi_trip
on taxi_trip.DriverId = driver_details.DriverId
and taxi_trip.PickupLAT != 0
and taxi_trip.DropLAT != 0
and taxi_trip.TotalFare != 0
where (date_format(taxi_trip.RequestDate,'%Y-%m-%d') >= 2015-07-17)
and (date_format(taxi_trip.RequestDate,'%Y-%m-%d') <= 2015-07-17)
and (driver_details.DriverId LIKE '%sa%'
or driver_details.Firstname LIKE '%sa%'
or driver_details.Lastname LIKE '%sa%'
or driver_details.TaxiPlateNo LIKE '%sa'
or count(taxi_trip.AutoId) LIKE '%sa%'
or sum(taxi_trip.TripDistance) LIKE '%sa%'
or sum(taxi_trip.TotalFare) LIKE '%sa%')
group by taxi_trip.AutoId
最佳答案
尝试使用 having
重写它select driver_details.DriverId,
count(taxi_trip.AutoId) AS TotalTrip,
sum(taxi_trip.TripDistance) AS TotalTripDistance,
sum(taxi_trip.TotalFare) AS TotalTripFare
from driver_details
left join taxi_trip
on taxi_trip.DriverId = driver_details.DriverId
and taxi_trip.PickupLAT != 0
and taxi_trip.DropLAT != 0
and taxi_trip.TotalFare != 0
group by taxi_trip.AutoId
having (date_format(taxi_trip.RequestDate,'%Y-%m-%d') >= 2015-07-17)
and (date_format(taxi_trip.RequestDate,'%Y-%m-%d') <= 2015-07-17)
and (driver_details.DriverId LIKE '%sa%'
or driver_details.Firstname LIKE '%sa%'
or driver_details.Lastname LIKE '%sa%'
or driver_details.TaxiPlateNo LIKE '%sa'
or count(taxi_trip.AutoId) LIKE '%sa%'
or sum(taxi_trip.TripDistance) LIKE '%sa%'
or sum(taxi_trip.TotalFare) LIKE '%sa%')
关于mysql - 如何在mysql中使用带计数值的like查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31474689/
我是一名优秀的程序员,十分优秀!