關於資料庫Group By取最新一條資料

2021-10-07 10:07:37 字數 994 閱讀 5141

根據欄位super_find_id分組查詢opt_time最新的一條資料,如以上示例表中期望查詢結果為第2條。

select

b.super_find_id,

max( b.opt_time ) as opt_time

from

info_super_feedback b

group by

b.super_find_id

查詢結果:

根據super_find_id欄位分組取opt_time欄位最新資料已成功,下一步是要取對應的全部字段值。

select

f.id,

f.feedback_content,

f.super_find_id,

f.opt_time

from

( select b.super_find_id, max( b.opt_time ) as opt_time from info_super_feedback b group by b.super_find_id ) b

inner join info_super_feedback f on f.super_find_id = b.super_find_id and f.opt_time = b.opt_time

查詢結果:

與未分組前的原始資料相比:

資料庫group by過濾

查詢歷史記錄的時候,比如1分鐘插入一條記錄,但是這些記錄基本相同,或者某些字段完全相同 我們想顯示在前端的希望過濾掉重複部分或者每隔20分鐘,或者5分鐘顯示一條 declare checktime datetime,intervartime int set checktime 2010 1 1 11...

oracle資料庫GROUP BY 子句

1.group by子句 在select 列表中所有未包含在組函式中的列都應該包含在group by 子句中.如下 select deptno,g sal from emp group by deptno deptno為沒有包含在組函式的列 以下查詢是錯誤的 select a,b,c,g sal f...

Access資料庫中Group by 語句特別之處

access資料庫中group by 語句特別之處 group by 語句在access資料庫中 與其在sql 2000等資料庫中的應用有區別,但最近發現了乙個特別的之處 group by 語句 會把分組後的字段內容自動縮減至小於255個字元數,如果你的字段內容超過它,那麼就會不提示你的情況下自動載...