❶ sql取出值最小的一條數據
補充樓上:
select min(欄位名稱)as 最小值 from 表名
❷ SQL從查詢結果中查最小值
SELECT C.CategoryID, C.CategoryName, SUM(F.CommentNO) AS SumComment
FROM Category AS C, Feedback AS F, Article AS A
WHERE C.CategoryID=A.CategoryID AND A.ArticleID=F.ArticleID
GROUP BY C.CategoryID, C.CategoryName having SUM(F.CommentNO)=
(select min(t1.SumComment1) from
(SELECT SUM(F.CommentNO) AS SumComment1
FROM Category AS C, Feedback AS F, Article AS A
WHERE C.CategoryID=A.CategoryID AND A.ArticleID=F.ArticleID
GROUP BY C.CategoryID, C.CategoryName) as t1)
這樣試試
❸ SQL 兩個欄位 取小的
SELECT id, CASE WHEN a > b then b else a end
from tab
❹ sql語句 同一時間出現2條數據,對比其中某一欄位,刪除其中較小的一條
delete from table where c in (select min(c) from table where a='13' and b='57')
這樣就可以取兩條數據 最小的數據進行刪除!
❺ sql 資料庫如何選取最小值,第二最小值,第三最小值........
排序後使用top1將排名第一的去除就是排名第二的,將排名前2的去除就是排名第三的
如同分頁的查詢一樣
❻ 用SQL語句查詢最小值,最大值不能用min,max函數怎麼查
1.
--大於等於所有(最大值)
select*fromApo_city
wherecity_id>=all(selectcity_idfromApo_city)
--小於等於所有(最小值)
select*fromApo_city
wherecity_id<=all(selectcity_idfromApo_city)
--2.
--降序取第一個(最大值)
select*fromApo_city
wherecity_id=(selecttop1city_idfromApo_cityorderbycity_iddesc)
--升序取第一個(最小值)
select*fromApo_city
wherecity_id=(selecttop1city_idfromApo_cityorderbycity_idAsc)
--3.
--最大值
selectTop1city_idfromApo_cityorderbycity_iddesc
--最小值
selectTop1city_idfromApo_cityorderbycity_idAsc
--4.
--最大值
WithT
As
(
select*,ROW_NUMBER()over(orderbycity_idDesc)asidfromApo_city
)
select*fromTwhereid=1
--最小值
WithT
As
(
select*,ROW_NUMBER()over(orderbycity_idAsc)asidfromApo_city
)
select*fromTwhereid=1
5.
--不小於任何一個(最大值)
select*fromApo_city
wherenotcity_id<any(selectcity_idfromApo_city)
--不大於任何一個(最小值)
select*fromApo_city
wherenotcity_id>any(selectcity_idfromApo_city)
❼ SQL語句求一個表中兩列數據中的最大/最小值/標准差
selectcase(
whenMAX(col1)>MAX(col2)then'col1大'
whenMAX(col1)<MAX(col2)then'col2大'
else'相等'end)asCOL1,
case(
whenMIN(col1)<MIN(col2)then'col1小'
whenMIN(col1)>MIN(col2)then'col2小'
else'相等'end)asCOL2,
case(
whenavg(col1)<avg(col2)then'col1品均小與col2'
whenavg(col1)>avg(col2)then'col2品均小與col1'
else'相等'end)asCOL3
fromtable1
❽ sql語句求兩個欄位都是最小值的那一條記錄
都最小?
你能保證id最小的記錄里成績也是最小的嘛?
如果是的話
select*fromtableorderbyidasc,gradeasclimit1
就可以了。
如果不是的話,你不能只找到1條記錄的,至少也是2條吧?