Jonathan 님이 쓰신 글 :
: Table 이름이 NT이고
: BB CC DD <- 필드명
: 1 1 10 <- 레코드 데이타
: 1 2 20
: 1 3 30
: 2 1 40
: 2 2 50
: 2 3 60
: 3 1 70
:
: 위에 값을 아래와 같이 하면
: select iif(cc = 1,dd,0), iif(cc=2,dd,0),iif(cc=3,dd,0) from nt group by bb,cc,dd
: 10 0 0
: 0 20 0
: 0 0 30
: 40 0 0
: 0 50 0
: 0 0 60
: 70 0 0
: 이렇게나옵니다.
: 저는 Group By 로 묶어서
: 10 20 30
: 40 50 60
: 70 0 0
: 이렇게 나오게 하려고 하는데 잘 안됩니다. Group by bb 만해주면 될것 같지만
:
: can't format message 13:896 -- message file C:\Program Files\HK-Software\IBExpert\firebird.msg not found.
: Dynamic SQL Error.
: SQL error code = -104.
: Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause).
:
: 이런 에러 가 나타납니다. 해결 방법좀 알려주세요 Firebird의 한계인가요?
select bb,
sum(case when cc = '1' then dd else 0 end) "값1" ,
sum(case when cc = '2' then dd else 0 end) "값2" ,
sum(case when cc = '3' then dd else 0 end) "값3"
from nt
group by bb
추신) FireBird 1.5 보다는 2.0이 훨신 유리합니다.
2.0에서는 다음과 같이 해도 됩니다.
select bb,sum("값1") "값1",sum("값2") "값2",sum("값3") "값3"
from
(
select bb,
case when cc = '1' then sum(dd) end "값1" ,
case when cc = '2' then sum(dd) end "값2" ,
case when cc = '3' then sum(dd) end "값3"
from nt
group by bb,cc
)
|