CREATE VIEW radio_detail_stc AS SELECT fk_radio_ou_no, SUM(wait_count) count_wait, 
                                           SUM(detail_count) count_detail
                                     FROM (SELECT a.fk_radio_ou_no, a.exam_detail_name, 
                                                   b.order_no, b.exam_status, 
                                                   CASE b.exam_status WHEN 'PENDING' THEN
                                                    1 ELSE 0 END wait_count, 
                                                   CASE WHEN b.order_no > 0 THEN 1 ELSE 0 END
                                                    detail_count
                                             FROM exam_detail a LEFT OUTER JOIN
                                                   schedule b ON 
                                                   a.exam_detail_no = b.fk_exam_detail_no) as a
                                     GROUP BY fk_radio_ou_no

解决方案 »

  1.   

    更正一下CREATE VIEW radio_detail_stc AS SELECT fk_radio_ou_no, SUM(wait_count) count_wait, 
                                               SUM(detail_count) count_detail
                                         FROM (SELECT a.fk_radio_ou_no, a.exam_detail_name, 
                                                       b.order_no, b.exam_status, 
                                                       CASE b.exam_status WHEN 'PENDING' THEN
                                                        1 ELSE 0 END wait_count, 
                                                       CASE WHEN b.order_no > 0 THEN 1 ELSE 0 END
                                                        detail_count
                                                 FROM exam_detail a LEFT OUTER JOIN
                                                       schedule b ON 
                                                       a.exam_detail_no = b.fk_exam_detail_no) as z
                                         GROUP BY fk_radio_ou_no
      

  2.   

    CREATE VIEW radio_detail_stc 
    AS 
    SELECT fk_radio_ou_no, SUM(wait_count) count_wait, 
       SUM(detail_count) count_detail
    FROM (
       SELECT a.fk_radio_ou_no, a.exam_detail_name, 
               b.order_no, b.exam_status, 
               CASE b.exam_status WHEN 'PENDING' THEN
                1 ELSE 0 END wait_count, 
               CASE WHEN b.order_no > 0 THEN 1 ELSE 0 END
                detail_count
         FROM exam_detail a LEFT OUTER JOIN
               schedule b ON 
               a.exam_detail_no = b.fk_exam_detail_no
    ) as tableAlias  --错在这,加个表别名
    GROUP BY fk_radio_ou_no
      

  3.   

    多谢大家了,难怪我把两个SELECT分开来写可以执行,合起来却不行了不过我还有个问题,第二个SELECT是生成一个临时表吧,为什么一定要起个别名么?还是因为用了GROUP?(在ORACLE里不需要)