濮阳杆衣贸易有限公司

主頁 > 知識庫 > MSSQL 多字段根據范圍求最大值實現方法

MSSQL 多字段根據范圍求最大值實現方法

熱門標簽:知名電銷機器人價格 電銷機器人公司 需要哪些牌照 長沙智能外呼系統 廣東防封卡外呼系統原理是什么 湖南電腦外呼系統平臺 外呼系統改進 分享百度地圖標注多個位置 地圖標注牌 菏澤語音電銷機器人加盟公司

-->Title:生成測試數據
-->Author:wufeng4552
-->Date :2009-09-21 15:08:41

declare @T table([Col1] int,[Col2] int,[Col3] int,[Col4] int,[Col5] int,[Col6] int,[Col7] int)
Insert @T
select 1,10,20,30,40,50,60 union all
select 2,60,30,45,20,52,85 union all
select 3,87,56,65,41,14,21
--方法1
select [col1],
       max([col2])maxcol
from
 (select [col1],[col2] from @t
  union all
  select [col1],[col3] from @t
  union all
  select [col1],[col4] from @t
  union all
  select [col1],[col5] from @t
  union all
  select [col1],[col6] from @t
  union all
  select [col1],[col7] from @t
 )T
where [col2] between 20 and 60  --條件限制
group by [col1]
/*
col1        maxcol
----------- -----------
1           60
2           60
3           56

(3 個資料列受到影響)

*/
--方法2
select [col1],
       (select max([col2])from
       (
        select [col2]
        union all select [col3]
        union all select [col4]
        union all select [col5]
        union all select [col6]
        union all select [col7]
       )T
       where [col2] between 20 and 60) as maxcol --指定查詢範圍
from @t
/*
(3 個資料列受到影響)
col1        maxcol
----------- -----------
1           60
2           60
3           56
*/

標簽:呼和浩特 福建 商洛 泉州 西寧 天水 珠海 美容院

巨人網絡通訊聲明:本文標題《MSSQL 多字段根據范圍求最大值實現方法》,本文關鍵詞  MSSQL,多,字段,根據,范圍,;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《MSSQL 多字段根據范圍求最大值實現方法》相關的同類信息!
  • 本頁收集關于MSSQL 多字段根據范圍求最大值實現方法的相關信息資訊供網民參考!
  • 推薦文章
    曲周县| 岳池县| 元朗区| 嘉荫县| 静安区| 枞阳县| 焉耆| 长武县| 玛曲县| 潢川县| 滦平县| 南澳县| 读书| 鹤壁市| 东方市| 奎屯市| 称多县| 明光市| 南康市| 罗山县| 新干县| 大竹县| 株洲县| 葵青区| 博客| 白城市| 商城县| 桐乡市| 图们市| 明光市| 邯郸县| 正镶白旗| 岳阳县| 桐乡市| 两当县| 静海县| 迁安市| 永善县| 新竹市| 清新县| 宁晋县|