我正在尝试生成一份报告,显示所有机构以及居住在特定机构中的学生人数。 (三张 table - 设施表、房间表和床位表)
这是我的模型:
public function report_Management(){
$query="SELECT e.owner, e.id as 'Establishment_ID', e.name, (SELECT COUNT(b.bed_no) FROM beds b, users u, establishment e, room r WHERE r.establishment_id = Establishment_ID) as 'Number Of Ateneans' FROM establishment e GROUP BY e.id";
return $this->db->query($query);
}
我尝试在内部 Select 语句中使用 e.id 作为“Establishment_ID”
最佳答案
$query="SELECT e.owner, e.id as 'Establishment_ID2', e.name, (SELECT COUNT(b.bed_no) FROM bed b, registrar u, room r WHEREEstablishment_ID2 = r.builtment_id AND r. room_id = b.room_id AND u.id = b.student_id) 作为来自机构 e GROUP BY e.id 的“Ateneans 人数””;
关于mysql - 是否可以在 Codeigniter 中使用外部选择的变量到内部选择中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26453821/