2014-11-05 48 views
0

我得到這個錯誤,我不知道如何使用它。簡單的解釋將不勝感激。錯誤:錯誤混合組列沒有組列

錯誤編號:1140

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause 

SELECT a.nim,b.nama_mahasiswa,c.j_sks,b.jurusan,b.kelas_program,e.status from tbl_dosen_wali a left join tbl_mahasiswa b on a.nim=b.nim left join (select k.nim,k.kd_jadwal,SUM(l.jum_sks) as j_sks from tbl_perwalian_detail k left join (select x.kd_jadwal, y.jum_sks from tbl_jadwal x left join tbl_mk y on x.kd_mk=y.kd_mk) as l on k.kd_jadwal=l.kd_jadwal) c on a.nim=c.nim left join tbl_perwalian_header e on a.nim=e.nim where a.kd_dosen='D001' group by a.nim 

Filename: C:\xampp\htdocs\krs\siakad\system\database\DB_driver.php 

Line Number: 330 

格式化的查詢:

SELECT a.nim, 
     b.nama_mahasiswa, 
     c.j_sks, 
     b.jurusan, 
     b.kelas_program, 
     e.status 
FROM tbl_dosen_wali a 
     LEFT JOIN tbl_mahasiswa b 
       ON a.nim = b.nim 
     LEFT JOIN (SELECT k.nim, 
         k.kd_jadwal, 
         Sum(l.jum_sks) AS j_sks 
        FROM tbl_perwalian_detail k 
         LEFT JOIN (SELECT x.kd_jadwal, 
              y.jum_sks 
            FROM tbl_jadwal x 
              LEFT JOIN tbl_mk y 
                ON x.kd_mk = y.kd_mk) AS l 
           ON k.kd_jadwal = l.kd_jadwal) c 
       ON a.nim = c.nim 
     LEFT JOIN tbl_perwalian_header e 
       ON a.nim = e.nim 
WHERE a.kd_dosen = 'D001' 
GROUP BY a.nim 
+0

http://stackoverflow.com/questions/1244169/mysql-1140-mixing-of-group-columns http://stackoverflow.com/questions/9547802/的可能重複混合組的列最小最大數與無組列是非法http://stackoverflow.com/questions/1712408/mixing-of-group-columns-with-no-group -列 – gvgvgvijayan 2014-11-05 05:00:56

回答

0

的錯誤說你需要使用GROUP BY在你的子查詢。

試試這個

SELECT a.nim, 
    b.nama_mahasiswa, 
    c.j_sks, 
    b.jurusan, 
    b.kelas_program, 
    e.status 
FROM tbl_dosen_wali a 
    LEFT JOIN tbl_mahasiswa b 
      ON a.nim = b.nim 
    LEFT JOIN (SELECT k.nim, 
        k.kd_jadwal, 
        Sum(l.jum_sks) AS j_sks 
       FROM tbl_perwalian_detail k 
        LEFT JOIN (SELECT x.kd_jadwal, 
             y.jum_sks 
           FROM tbl_jadwal x 
             LEFT JOIN tbl_mk y 
               ON x.kd_mk = y.kd_mk) AS l 
          ON k.kd_jadwal = l.kd_jadwal 
          GROUP BY k.nim 
          ^^^^^^^^^^^^^^^^ 
          ) c 
      ON a.nim = c.nim 
    LEFT JOIN tbl_perwalian_header e 
      ON a.nim = e.nim 
WHERE a.kd_dosen = 'D001' 
GROUP BY a.nim