(SELECT COUNT(motorbike.`owner_id`) as count,owner.`name`,transport.`type` FROM transport,owner,motorbike WHERE transport.type='motobike'
AND owner.`owner_id`=motorbike.`owner_id`
AND transport.`type_id`=motorbike.`motorbike_id` GROUP BY motorbike.owner_id)
UNION ALL
(SELECT COUNT(car.`owner_id`) as count,owner.`name`,transport.`type` FROM transport,owner,car WHERE transport.type='car'
AND owner.`owner_id`=car.`owner_id`
AND transport.`type_id`=car.`car_id` GROUP BY car.`owner_id`)
La requête renvoie au-dessus d'un tel résultat ci-dessous,groupe par l'union mysql select requête
count name
1 Linda
2 Mary
1 Steve
1 Linda
Cette requête est de compter combien de transport qui appartient à un propriétaire. Linda ont une voiture et une moto, de sorte que le résultat devrait:
count name
2 Linda
2 Mary
1 Steve
J'ai essayé cette requête, mais renvoie une erreur:
(SELECT COUNT(motorbike.`owner_id`),owner.`name`,transport.`type` FROM transport,owner,motorbike WHERE transport.type='motobike'
AND owner.`owner_id`=motorbike.`owner_id`
AND transport.`type_id`=motorbike.`motorbike_id`)
UNION ALL
(SELECT COUNT(car.`owner_id`),owner.`name`,transport.`type` FROM transport,owner,car WHERE transport.type='car'
AND owner.`owner_id`=car.`owner_id`
AND transport.`type_id`=car.`car_id`) GROUP BY motorbike.owner_id
Quelqu'un peut-il me aider s'il vous plaît?
Son travail .. Merci beaucoup;) – user1103332
Une façon simple de le faire, mais je n'aurais jamais pensé à cela. Impressionnant! – alanaktion
Comment ajoutez-vous l'ordre et la limite à? –