¾Æ·¡ Äõ¸®¹® ½ÇÇà½Ã °á°ú°ªÀÌ ¾Æ·¡¿Í °°ÀÌ Ãâ·Â°ªÀ» ¿ìÃø°ú °°ÀÌ º¯°æÇÏ°í ½Í½À´Ï´Ù.
B±×·ì¿¡¼ Á¶°ÇÀ» º¯°æÇÏ´Ï °°Àº°ªÀÌ µé¾î°¡ Ãâ·Â°ªÀÌ µ¿ÀÏÇÏ°Ô ÂïÈ÷°í ¹æ¹ýÀ» ¸øã°Ú³×¿ä..
Ȥ½Ã ¾Æ½Ã´ÂºÐ ÀÖÀ»±î¿ä?
select BIZ_CODE, A.m2 as mm, A.dd as dd,
case when bad_m1 = 0 then 100 when PROD_M1 is null then 0 else (1 - (bad_m1 / nullif (PROD_M1 + BAD_M1, 0))) * 100 end as val1
from ((
select distinct YYYYMM, M2, dd
from aaaa
where yyyy = '2016' and yyyymm = '201612') A left join (
select yyyymm, dd, BIZ_CODE as BIZ_CODE, sum(prod_m2) as prod_m1, sum(bad_m2) as bad_m1
from bbbb
where YYYY = '2016' and YYYYMM <= '201612'
and biz_code like '%'
group by yyyymm, dd, BIZ_CODE) B on A.dd = B.dd
and a.YYYYMM = b.YYYYMM)
order by mm, dd
|
SUM(CASE WHEN BIZ_CODE = '11' THEN VAL1 ELSE 0 END) AS VAL1,
SUM(CASE WHEN BIZ_CODE = '12' THEN VAL1 ELSE 0 END) AS VAL2
FROM (
ÇöÀçÄõ¸®°á°ú
)
GROUP BY MM, DD