如何在Joomla中执行此查询?
Select student_id, ( select count(Subj_Code)
from grade b
where a.grade=b.grade and a.student_id=b.student_id) as subjectcount
from grade a where a.student_id='$student_id';
答案 0 :(得分:0)
如果您正在寻找子查询,那么您需要为它创建一个新对象。以下是示例 -
$subQuery = $db->getQuery(true);
$subQuery->select('count(Subj_Code)');
$subQuery->from($db->quoteName('grade') . ' as b');
$subQuery->where('a.grade=b.grade and a.student_id=b.student_id');
$query = $db->getQuery(true);
$query->select('student_id');
$query->select('(' . $subQuery . ') as subjectcount');
$query->from($db->quoteName('grade') . ' as a');
$query->where('a.student_id = ' . $db->quote($student_id));