【发布时间】:2019-03-30 19:12:39
【问题描述】:
我有两张桌子,例如:
tbl student :
.................
id | Name |Age |
.................
1 | A |15 |
2 | B |13 |
3 | C |12 |
.................
另一个表,例如 Tbl_student_details :
.......................
id | stud_id |section |
.......................
1 | 1 |A |
2 | 1 |B |
3 | 2 |C |
.......................
Result Expected:
Active student : count (2) because id 1 and 2 have records in student detail table
Inactive Student :count(1) dont have any record in student detail table
我需要得到的是我想要活跃或不活跃的学生..
如果任何学生在 student_details 中有记录,则需要这些学生的数量以及非活动学生的数量 哪个学生在学生详细信息表中没有记录我需要计算这些学生以及非活动学生的数量 我怎样才能让这个活跃和不活跃的学生有任何想法我需要在 laravel DB:: raw 中进行查询,如果不可能的话,只是建议我查询,请帮助我与此相关..
【问题讨论】:
-
根据您的样本数据,预期的输出是什么?此外,从长远来看,存储 Age 没有任何意义,否则您将不得不每年自动递增它
-
对非活动使用左连接,
IS NULL Tbl_student_details.id使用标准连接(INNER JOIN)用于其他连接。 -
你在使用 laravel 关系吗?
-
上尉。提莫@使用 DB:raw
-
在您的模型中。你们有关系吗?