tbl_appointment_book
计算client_id,但tbl_appointment_book
' id
和tbl_appointment_service
' s appointment_id
应匹配。
tbl_appointment_book
id appointment_date client_id status
1 2016-05-11 1 1
2 2016-05-12 1 1
tbl_appointment_service
id appointment_id service_id team_id
1 1 1 1
2 1 2 1
3 1 8 5
4 2 1 1
5 2 1 2
我想从client_id
条件开始计算tbl_appointment_book
appointment_date=2016-05-11, team_id=1
答案 0 :(得分:0)
尝试以下查询,它应该可以正常工作。
SELECT COUNT (tab.client_id)
FROM tbl_appointment_book tab
JOIN tbl_appointment_service tas
ON tab.id = tas.appointment_id
WHERE tab.appointment_date = '2016-05-11' AND tas.team_id = 1;
答案 1 :(得分:0)
您可以使用JOIN
来实现您想要的结果:
SELECT count(a.client_id) FROM tbl_appointment_book a
JOIN tbl_appointment_service b
ON a.id = b.appointment_id
WHERE a.appointment_date = '2016-05-11' AND b.team_id = 1
结果将是返回的行数。