① sql 最小值選取
select min(left_day),atrate from Act_Table
where Act=1 group by atrate
② 用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求某一欄位中最大值和最小值的問題,高手請進!
sql查詢欄位的最大值使用max()函數。
例:select
max(a)
from
table
語句大意:檢索表table中a欄位中的最大值。
(3)sql取某一項目最小值擴展閱讀:
1、SQL數據定義功能:能夠定義資料庫的三級模式結構,即外模式、全局模式和內模式結構。在SQL中,外模式又叫做視圖(View),全局模式簡稱模式( Schema),內模式由系統根據資料庫模式自動實現,一般無需用戶過問。
2、SQL數據操縱功能:包括對基本表和視圖的數據插入、刪除和修改,特別是具有很強的數據查詢功能。
3、SQL的數據控制功能:主要是對用戶的訪問許可權加以控制,以保證系統的安全性。
④ 如何在SQL中查詢最大值與最小值
select max(氣溫),min(氣溫) from 氣溫表;
哈哈
⑤ 如何用sql語句查出最大值、最小值等
select max(t) as 溫度最大值,min(t) as 溫度最小值,max(p) as 濕度最大值,min(p) as 濕度最小值,max(datetime) as 最後出現時間,min(datetime) as 最早出現時間 from yourtable_name
⑥ 求sql語句 多列取最小值
請查閱這里:求最小值的方法
裡面舉三個例子:
1 使用values子句生成臨時表
2使用行列轉換
3使用union all拼接臨時表
createtabletest
(namevarchar(10),time1int,time2int,time3int)
insertintotest(name,time1,time2,time3)
values
('a',1,2,3), ('b',8,9,6), ('c',11,22,8), ('d',101,201,38),
('e',6,7,9), ('f',8,8,13), ('g',2,2,30), ('h',82,56,53)
go
---方法1:使用values子句構建臨時表
selectname,(selectmin(timeMin)from(values(time1),(time2),(time3))as#temp(timeMin))astimeMinfromtest
---方法2行轉列
selectname,min(timeMin)as[最小數]fromtestunpivot(timeMinfortimeMintin(time1,time2,time3))asugroupbyname
--方法3:使用unionall組合新表
selectname,(selectmin(timeMin)
as[最小數]from(
selecttest.time1astimeMin
unionall
selecttest.time2
unionall
selecttest.time3)ud)
MaxDatefromtest
go
droptabletest
如有疑問,及時溝通!
⑦ sql取最大值和最小值
select
g_table.max_so2
,t_so2.date
,g_table.min_so2
,t_so2_min.date
....
(
select
max(so2) max_so2
,min(so2) min_so2
,max(pm2.5) max_pm25
,min(pm2.5) min_pm25
...
,max(co) max_no2
,min(co) min_co
from table_name
) g_table
,table_name t_so2
,table_name t_so2_min
...
where g_table.max_so2 = t_so2.so2(+)
and g_table.min_so2 = t_so2_min.so2(+)
....
你這個需求有點費勁,這樣能實現,但是效率很低。
⑧ 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 top 300 * from 表名 order by desc
select top 300 * from 表名 order by asc
' 為列名
⑩ SQL取出值最小的一條數據
補充樓上:
select min(欄位名稱)as 最小值 from 表名