内部結合で。
select A.id,A.name,A.comment,
count(B.id) as cnt,
max(B.date) as date,
'0' as CK
from A,B
where B.id=A.id and not exists(
select id from C where C.id=A.id
)
group by A.id,A.name,A.comment
UNION
select A.id,A.name,A.comment,
0 as cnt,
NULL as date,
'0' as CK
from A
where not exists(
select id from C where C.id=A.id
)
and not exists(
select id from B where B.id=A.id
)
group by A.id,A.name,A.comment
UNION
select A.id,A.name,A.comment,
count(B.id) as cnt,
max(B.date) as date,
'1' as CK
from A,B,C
where B.id=A.id and C.id=A.id
group by A.id,A.name,A.comment
UNION
select A.id,A.name,A.comment,
0 as cnt,
NULL as date,
'1' as CK
from A,C
where C.id=A.id and not exists(
select id from B where B.id=A.id
)
group by A.id,A.name,A.comment
order by CK,cnt;
お礼
こんなにいっぱい書いていただきありがとうございます。 でも、できませんでした。。なんででしょう。。 adding missing FROM-clause entry in subquery for table "A"