SQL查詢最大值,返回整行資料

2021-09-24 15:50:12 字數 513 閱讀 2012

部分資料如下,未完整展示。如何從table_a表中查詢p_postions列的最大值對應的一行資料?

方法1:先排序,再取第一條

select

*from table_a order

by p_postions desc

limit

1;

參考:

這是一種時間複雜度為o(n)的方法:

select

*from

table_a

where

p_postions =

(select

max(p_postions)

from table_a)

limit

1;

sql多表查詢分組最大值

問題描述 有三張表 學生表student id,name id為主鍵 課程表subject id,name id為主鍵 分數表score studentid,subjectid,score 其中studentid與subjectid為聯合主鍵,一句sql語句查詢出 學號,姓名,課程名,課程最高分.模...

SQL分組最大值

employee表包含所有員工資訊,每個員工有其對應的 id,salary 和 department id。id name salary departmentid 1 joe 70000 1 2 henry 80000 2 3 sam 60000 2 4 max 90000 1 department...

SQL分組求最大值

訂單操作記錄表,需要獲取每個訂單最新的操作更新時間,以及操作id。使用 over 以及 row number 來實現 select from select operationid,orderno,updatetime,row number over partition by orderno orde...