❶ 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条吧?