sql - 如何查找不同表中的行数
问题描述
我想从两个不同的表中获取数据 一个表包含学生总数 另一个表包含特定的学生信息 我如何获得我想要显示的学生人数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
此查询显示错误请指导我谢谢
解决方案
试试下面 - 你的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
推荐阅读
- arrays - 如何在 JSON 字符串变量中选择多行?
- api - 如何在 nuxt.js 中发送带有参数的发布请求?
- admob - 未显示欧盟同意对话框
- javascript - 如何在单击事件中附加和删除 Font Awesome 图标(Javascript)
- javascript - Chrome 扩展程序:net::ERR_CONNECTION_REFUSED
- beautifulsoup - 为什么 BeautifulSoup 给我一个数字,而不是代码?
- google-cloud-platform - 在 Cloud Run 中运行 RabbitMQ 时出错 -> 未捕获信号:10,pid=418,tid=418,fault_addr=0
- python - 'Context' 和 'int' 的实例之间不支持不和谐 '>'
- node.js - 在nodejs中将记录集解析为var
- android - 如何将 2 个不同的媒体列表一一上传到 Firebase 存储?