1
我想選擇一個布爾值,其中order.lastUpdated是超過30分鐘前,但我得到的錯誤:MySQL的無效使用組功能與MAX()
SQL state [HY000]; error code [1111]; Invalid use of group function; nested exception is java.sql.SQLException: Invalid use of group function
下面是該查詢:
select
c.externalReference channelReference,
c.id channelId,
max(o.lastUpdated) lastUpdated,
sum(if(max(o.lastUpdated) < date_sub(now(), interval 30 minute), 0, 1)) beforeThreshold
from channel c
join order_item o on c.id = o.channelId
where date(o.lastUpdated) = date(now())
and o.lastUpdated > date_sub(now(), interval 1 hour)
group by c.externalReference;
我怎樣才能返回一個布爾值,如果o.lastUpdated
是超過30分鐘前,我必須使用max()
?
先試試c.externalReference,c.id然後看看有沒有什麼區別 – Moptan
我仍然得到同樣的錯誤。 – crm
您不能嵌套集合函數('sum(max)'),'max'必須在Derived Table中完成,而'Sum'在其上。 – dnoeth