SELECT *
FROM
(
SELECT stat,
SUM(DECODE(visa_country,'US',1,0)) AS USA,
SUM(DECODE(visa_country,'United Kingdom',1,0)) AS UK,
SUM(DECODE(visa_country,'Australia',1,0)) AS Australia,
SUM(DECODE(visa_country,'Canada',1,0)) AS Canada,
SUM(DECODE(visa_country,'Switzerland',1,0)) AS Switzerland,
SUM(DECODE(visa_country,'Singapore',1,0)) AS Singapore,
SUM(DECODE(visa_country,'Sweden',1,0)) AS Sweden,
SUM(DECODE(visa_country,'Netherlands',1,0)) AS Netherlands
FROM
(
SELECT *
FROM
(
SELECT stat,
visa_country,
DECODE(stat,'>= 0 '||'&'||' < 15', 1
,'>= 15 '||'&'||' < 30',2
,'>= 30 '||'&'||' < 45',3
,'>= 45 '||'&'||' < 60',4
,'>= 60 '||'&'||' < 75',5
,'>= 75 '||'&'||' < 90',6
,' >= 90',7) AS gr
FROM (
SELECT end_date,
visa_country,
CASE WHEN END_DATE between 0 and 14 THEN '>= 0 '||'&'||' < 15'
WHEN END_DATE BETWEEN 15 AND 29 THEN '>= 15 '||'&'||' < 30'
WHEN END_DATE BETWEEN 30 AND 44 THEN '>= 30 '||'&'||' < 45'
WHEN END_DATE BETWEEN 45 AND 59 THEN '>= 45 '||'&'||' < 60'
WHEN END_DATE BETWEEN 60 AND 74 THEN '>= 60 '||'&'||' < 75'
WHEN END_DATE BETWEEN 75 AND 89 THEN '>= 75 '||'&'||' < 90'
WHEN END_DATE > 90 THEN ' >= 90'
END AS stat
FROM
(
SELECT visa_country,
GREATEST(
NVL(TO_DATE(VP.WP_VALID_TILL,'DD-MON-YY'),TO_DATE(SYSDATE,'DD-MON-YY')),
NVL(TO_DATE(VP.VISA_VALID_TILL,'DD-MON-YY'),to_DATE(SYSDATE,'DD-MON-YY'))
)
- TO_DATE(SYSDATE,'DD-MON-YY') AS END_DATE
FROM visa_prac AS vp
)
) AS x
WHERE x.end_date > 0
)
) GROUP BY stat
ORDER BY gr
)
这是给出雇员数量的代码......但问题是,如果任何计数为零,则不会显示整行.......
没有详细信息属于&gt; = 75&amp;的范围。 &lt; 90然后该行没有显示..
非常感谢您的帮助解决它。
答案 0 :(得分:0)
我认为您需要删除END
中的WHERE
子句
WHERE x.end_date >0
因为它在ZERO的情况下过滤了行。
select * from
(
select stat, sum(decode(visa_country,'US',1,0))USA,
sum(decode(visa_country,'United Kingdom',1,0))UK,
sum(decode(visa_country,'Australia',1,0))Australia,
sum(decode(visa_country,'Canada',1,0)) Canada,
sum(decode(visa_country,'Switzerland',1,0))Switzerland,
sum(decode(visa_country,'Singapore',1,0))Singapore,
sum(decode(visa_country,'Sweden',1,0))Sweden,
sum(decode(visa_country,'Netherlands',1,0))Netherlands
from
(
select * FROM
(
SELECT stat,visa_country,DECODE(stat,'>= 0 '||'&'||' < 15',1,'>= 15 '||'&'||' < 30',2,'>= 30 '||'&'||' < 45',3,'>= 45 '||'&'||' < 60',4,'>= 60 '||'&'||' < 75' ,5,'>= 75 '||'&'||' < 90' ,6,' >= 90',7)gr
from (
select end_date,visa_country,case when END_DATE between 0 and 14 THEN '>= 0 '||'&'||' < 15'
when END_DATE BETWEEN 15 AND 29 THEN '>= 15 '||'&'||' < 30'
When END_DATE BETWEEN 30 AND 44 THEN '>= 30 '||'&'||' < 45'
When END_DATE BETWEEN 45 AND 59 THEN '>= 45 '||'&'||' < 60'
When END_DATE BETWEEN 60 AND 74 THEN '>= 60 '||'&'||' < 75'
When END_DATE BETWEEN 75 AND 89 THEN '>= 75 '||'&'||' < 90'
When END_DATE > 90 THEN ' >= 90'
END stat
from (select visa_country,GREATEST(nvl(TO_DATE(VP.WP_VALID_TILL,'DD-MON-YY'),to_DATE(sysdate,'DD-MON-YY')),NVL(TO_DATE(VP.VISA_VALID_TILL,'DD-MON-YY'),to_DATE(sysdate,'DD-MON-YY')))
-to_DATE(sysdate,'DD-MON-YY') AS END_DATE from visa_prac vp )
)x
)
) group by stat
order by gr
)