對于 product_code、site_name、station_type 和 created_at 的組合,我想選擇具有最大 dist_sn 的行。
這是我的代碼。
Select a.* from insight_info a,
(select insight_info.id,product_code, site_name, station_type,
created_at = (SELECT DATE(created_at) from insight_info),
max(dist_sn)
from insight_info
group by product_code, site_name, station_type,insight_info.id,
created_at= (SELECT DATE(created_at) from insight_info)) b
where a.product_code = b.product_code
and a.site_name = b.site_name
and a.station_type = b.station_type
and a.created_at = b.created_at
and a.product_code ='D00'
and a.site_name = 'F00'
and a.station_type='A00';
這是我得到的錯誤。 錯誤:列 b.created_at 不存在第 10 行:和 a.created_at = b.created_at
如果不將 created_at 時間戳轉換為日期,則查詢運行不會出錯。但仍然沒有給出想要的輸出。它拾取了所有 dist_sn 而不僅僅是該組中的最大值。
uj5u.com熱心網友回復:
因此,修復錯誤所需要做的就是在內部查詢中放置一個別名。所以你的內部查詢從
(SELECT DATE(created_at) from insight_info)) b
到
(SELECT DATE(created_at) as created_at from insight_info)) b
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/458879.html
下一篇:弧-資料建模
