最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MSSQL 多字段根據(jù)范圍求最大值實現(xiàn)方法

 更新時間:2009年09月21日 18:37:27   作者:  
MSSQL 多字段根據(jù)范圍求最大值實現(xiàn)語句,大家可以參考下

-->Title:生成測試數(shù)據(jù)
-->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
*/

相關(guān)文章

最新評論

华蓥市| 石柱| 会理县| 大余县| 宁陵县| 沙雅县| 肥乡县| 瓦房店市| 永宁县| 石阡县| 六枝特区| 疏附县| 仁布县| 涿鹿县| 商洛市| 江安县| 磐安县| 玉龙| 汶川县| 晋宁县| 茌平县| 介休市| 罗平县| 怀宁县| 阿拉善盟| 敦煌市| 许昌县| 丰台区| 芦山县| 和林格尔县| 寻甸| 夏邑县| 和政县| 宁国市| 玉林市| 芜湖市| 眉山市| 佛学| 平潭县| 黄大仙区| 卫辉市|