【问题标题】:sub query return more than one row子查询返回多行
【发布时间】:2016-08-24 04:20:21
【问题描述】:
 select id, first_name, family_name, eq_id,
        date_of_birth, gender, indigenous, eal_d,
        atsi, icp, disability_category,
        (select raw_score
         from path_maths_term0 as T0
         where T0.eq_id=S.eq_id and year=2011
        ) as raw_score_2011term1,
       (select raw_score 
        from path_maths_term0 as T0
        where T0.eq_id=S.eq_id and year=2011
       ) as raw_score_2011term1,
       (select scale_score 
        from path_maths_term0 as T0
        where T0.eq_id=S.eq_id and year=2011
       ) as scale_score_2011term1,
       (select percentile 
        from path_maths_term0 as T0
        where T0.eq_id=S.eq_id and year=2011
       ) as percentile_2011term1,
       (select stanine 
        from path_maths_term0 as T0
        where T0.eq_id=S.eq_id and year=2011 
      ) as stanine_2011term1,
      class 
      from student_details as S
      where S.school_id ="SCH00001" and S.class = " 5B"

【问题讨论】:

  • 任何正文都可以帮助我了解在哪里更改此查询
  • 在查询中使用LIMIT 1
  • 非常感谢它的工作!
  • 你为什么使用子查询和查询表path_maths_term0 5 次,你可以使用连接在 1 个镜头中完成?

标签: php mysql codeigniter mysqli codeigniter-3


【解决方案1】:

在您的子查询中使用LIMIT 1,例如

select raw_score from path_maths_term0 as T0 where T0.eq_id=S.eq_id and year=2011 LIMIT 1

【讨论】:

    【解决方案2】:

    试试这个

    select id, first_name, family_name, eq_id, date_of_birth, gender, indigenous, eal_d, atsi, icp, disability_category,
    
    (select raw_score from path_maths_term0 as T0 where T0.eq_id=S.eq_id and T0.year=2011 ) as raw_score_2011term1,
    (select scale_score from path_maths_term0 as T0 where T0.eq_id=S.eq_id and T0.year=2011 ) as scale_score_2011term1,
    
    (select percentile from path_maths_term0 as T0 where T0.eq_id=S.eq_id and T0.year=2011 ) as percentile_2011term1,
    
    (select stanine from path_maths_term0 as T0 where T0.eq_id=S.eq_id and T0.year=2011 ) as stanine_2011term1,
    class from student_details as S
     where S.school_id ="SCH00001" and S.class = " 5B"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      相关资源
      最近更新 更多