gpt4 book ai didi

mysql - 如何在mysql中使用带计数值的like查询

转载 作者:行者123 更新时间:2023-11-29 03:30:21 24 4
gpt4 key购买 nike

我想在点赞搜索中使用一个表的计数值。我能怎么做?这是我的查询,它显示 #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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com