CREATE OR REPLACE PACKAGE BODY pr_nb
AS
   PROCEDURE show_nb_cursor (io_cursor OUT t_cursor)
   AS
   BEGIN
      OPEN io_cursor FOR
  select product_id,product_name, max(out_time) as out_time , back_time, user_id, user_tel,image from
  (
         SELECT m_nblog.product_id, a.product_name, out_time, back_time,user_id, user_tel, a.image
           FROM m_nblog,
                (SELECT image, product_name
                   FROM m_notebook, m_nblog
                  WHERE m_notebook.product_id = m_nblog.product_id) a
           WHERE product_id IN (SELECT product_id
                                 FROM m_notebook
                                WHERE product_flg = 1));
  group by product_id,product_name, out_time, back_time, user_id,user_tel,image;
   END show_nb_cursor;
END pr_nb;为什么总是说我的 group by 有问题?帮忙看一下,那里有问题?

解决方案 »

  1.   

    out_time仅仅作为max(out_time) 的别名,故在group by 语句中不能加入属性字段out_time
    将“group by product_id,product_name,   out_time,   back_time,   user_id,user_tel,image;”
    改为“group by product_id,product_name, back_time,   user_id,user_tel,image;”
      

  2.   

                                                                    WHERE   product_flg   =   1)); 
        group   by   product_id,product_name,   out_time,   back_time,   user_id,user_tel,image; 大哥, 你这里两行都有分号