missing row in oracle
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,开发者_StackOverflow
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
)
This is the code which gives the count of the employees ... But the problem here is that if any count is zero it is not showing that entire row....
Supppose no details falls in the range of >=75 & <90 then that row is not showing up..
Will be grateful for your kind help resolving it.
I think you need to remove the WHERE
clause in the END
WHERE x.end_date >0
Because it is filtering out the rows in case of 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
)
精彩评论