首页 > 解决方案 > 如何查找不同表中的行数

问题描述

我想从两个不同的表中获取数据 一个表包含学生总数 另一个表包含特定的学生信息 我如何获得我想要显示的学生人数name , code, totalstudent and no.of ngo student

select 
       a.name as name, a.school_code as CODE, 
       a.num_of_student as totalstudent,
       b.COUNT (ngo_student_name) as total_student 
from 
      ngo_student as a 
      INNER JOIN student_details as b on a.name=b.ngo_student_name 
GROUP BY
      b.ngo_student_name

此查询显示错误请指导我谢谢

标签: sqlpostgresql

解决方案


试试下面 - 你的count(b.ngo_student_name)而不是选择列表中的b.count(ngo_student_name) 其他列也应该在group by子句中

select 
       a.name as name, a.school_code as CODE, 
       count(a.num_of_student) as totalstudent,
       COUNT(b.ngo_student_name) as total_student 
from 
      ngo_student as a 
      INNER JOIN student_details as b on a.name=b.ngo_student_name 
GROUP BY
      a.name,a.school_code

推荐阅读