error : #1242 - Subquery returns more than 1 row

前端 未结 4 617
夕颜
夕颜 2020-12-11 11:39

I got an error: #1242 - Subquery returns more than 1 row when i run this sql.

CREATE VIEW test 
AS 
  SELECT cc_name, 
         COUNT() AS total, 
         (         


        
4条回答
  •  清歌不尽
    2020-12-11 11:50

    SELECT COUNT() 
              FROM   bed 
              WHERE  respatient_id > 0 
              GROUP  BY cc_name
    

    You need to remove the group-by in the sub query, so possibly something like

    SELECT COUNT(*) 
              FROM   bed 
              WHERE  respatient_id > 0 
    

    or possibly -- depending on what your application logic is....

    SELECT COUNT(*) from (
              select count(*),cc_name FROM   bed 
              WHERE  respatient_id > 0 
              GROUP  BY cc_name) filterview
    

提交回复
热议问题