啊,还有一个问题,像这样的语句
select count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('103','401','303')then 1 end)as a1,
count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('104','402','304')then 1 end)as a2,
count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('105','403','305')then 1 end)as a3,
count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('106','404','306')then 1 end)as a4,
count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('107','405','307')then 1 end)as a5,
count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('108','406','308')then 1 end)as a6,a1+a2+a3+a4+a5+a6
 from (select sn,c_ltlb,c_lthxsdyjb from t_ryltxx where c_ltlb in
('60','61','74')) t;
为什么提示a6无效呢,oracle不支持这样写吗?

解决方案 »

  1.   

    select count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('103','401','303')then 1 end)as a1,
    count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('104','402','304')then 1 end)as a2,
    count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('105','403','305')then 1 end)as a3,
    count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('106','404','306')then 1 end)as a4,
    count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('107','405','307')then 1 end)as a5,
    count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('108','406','308')then 1 end)as a6,count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('103','401','303')then 1 end) 
    + count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('104','402','304')then 1 end)
    + count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('105','403','305')then 1 end)
    + count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('106','404','306')then 1 end)
    + count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('107','405','307')then 1 end)
    + count(case when t.c_ltlb='60' and t.c_lthxsdyjb in('108','406','308')then 1 end)
    from (select sn,c_ltlb,c_lthxsdyjb from t_ryltxx where c_ltlb in
    ('60','61','74')) t;不能在同一层中使用刚刚命名的别名