日期:2014-05-17 浏览次数:21047 次
select decode(sign(sal - 2000), -1, sal, 0, sal) a, --sal <=2000
decode(sign(sal - 3000), -1, decode(sign(sal - 2000), 1, sal)) b, --sal 2000 to 3000
decode(sign(sal - 3000), 1, sal, 0, sal) c --sal >= 3000
from emp;
--相应数据改下就行
/*
sign()函数判断表示结果0、正数还是负数,分别返回0、1、-1 ,例如:
引用
a=10,b=20
则sign(a-b)返回-1
*/
select to_char(count(a)),to_char(count(b)),to_char(count(c)),to_char(count(d)),to_char(count(e)) from (
select decode(sign(TOTAL_GROSS_WEIGHT - 45), -1, TOTAL_GROSS_WEIGHT, 0, TOTAL_GROSS_WEIGHT) a, --sal <=2000
decode(sign(TOTAL_GROSS_WEIGHT - 100), -1, decode(sign(TOTAL_GROSS_WEIGHT - 45), 1, TOTAL_GROSS_WEIGHT)) b, --sal 2000 to 3000
decode(sign(TOTAL_GROSS_WEIGHT - 300), -1, decode(sign(TOTAL_GROSS_WEIGHT - 100), 1, TOTAL_GROSS_WEIGHT)) c,
decode(sign(TOTAL_GROSS_WEIGHT - 500), -1, decode(sign(TOTAL_GROSS_WEIGHT - 300), 1, TOTAL_GROSS_WEIGHT)) d,
decode(sign(TOTAL_GROSS_WEIGHT - 500), 1, TOTAL_GROSS_WEIGHT, 0, TOTAL_GROSS_WEIGHT)e,SHIP_TO,REQUEST_DATE --sal >= 500
from ASN_MST WHERE PK_NO LIKE '%GG0112%' and REQUEST_DATE>'20120301' and REQUEST_DATE<'20120331')