我有一张名为delivery的表 -
id | driver_id | depart_loc | arrive_loc | depart_time | arrive_time
然后..我有另一张关于交付项目的表格
id | delivery_id | item_id | serial
如何选择交付和项目表,以便它就像这样
driver_id | arrive_loc | arrive_time | total_item_found_in_delivery
甚至可能吗?
答案 0 :(得分:1)
我设法完成了它。以下选择做了诀窍(好吧......或多或少)
SELECT driver_id, arrive_loc, arrive_time, itemcount
FROM (SELECT delivery.driver_id as driver_id, COUNT(items.id) AS itemcount, delivery.arrive_loc as arrive_loc,
delivery.arrive_time as arrive_time
FROM delivery
LEFT JOIN items
ON delivery.id = items.delivery_id
GROUP BY delivery.arrive_loc) AS A
Thanx家伙!