我有2张桌子。一个被称为subscriptions
,另一个被称为service_sushi_service
。我正在尝试获取所有具有 2 种以上不同的手机service_id
。例如。
phone: 12345 service id: 12
phone: 12345 service id: 12
phone: 12345 service id: 8
phone: 12345 service id: 8
phone: 12345 service id: 13
phone: 22222 service id: 13
phone: 22333 service id: 3
我需要将其输出为 phone=12345,occurrences=3
这就是我到目前为止所得到的:我不知道如何走得更远。
SELECT
`sub`.`phone` AS `phone`
FROM
`subscriptions` AS `sub`
LEFT JOIN `service_sushi_service` `sushi_service` ON `sushi_service`.`sushi_service_id` = `sub`.`sushi_service_id`
WHERE
date(`sub`.`added`) >= '2013-01-01'
GROUP BY `sub`.`phone`