最新国产好看的视频,伊人天堂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 --指定查詢範(fàn)圍
from @t
/*
(3 個資料列受到影響)
col1        maxcol
----------- -----------
1           60
2           60
3           56
*/

相關(guān)文章

最新評論

新晃| 长顺县| 锦州市| 谷城县| 南溪县| 彭水| 洪湖市| 安岳县| 海晏县| 泾阳县| 射洪县| 平武县| 四会市| 秭归县| 许昌市| 南通市| 凌云县| 通榆县| 博湖县| 开江县| 武隆县| 田东县| 乐至县| 杨浦区| 斗六市| 桂阳县| 周宁县| 三河市| 高要市| 肇东市| 台中市| 天全县| 庆安县| 屏南县| 大冶市| 安康市| 云霄县| 都江堰市| 全椒县| 万宁市| 绥江县|