有没有办法可以在cd.date_id下面使用distinct?它正在连接,但我也想要不同的功能,所以它就像GROUP_CONCAT( CAST( distinct(cd.date_id) AS CHAR ) ) As date_id
但它似乎不起作用......
SELECT b.bar_id, b.bar_name, b.bar_image, b.bar_lat, b.bar_lng, b.bar_address,
b.bar_phone, b.bus_web, b.bar_open_hours, c.coupon_id, c.coupon_text,
bc.coupon_start_time, bc.coupon_exp_time,
GROUP_CONCAT( CAST( cd.date_id AS CHAR ) ) As date_id,
d.calender_date, bc.bc_id, bc.priority As priority
FROM bars b
JOIN bars_coupons bc ON (bc.bar_id = b.bar_id)
JOIN coupons c ON (bc.coupon_id = c.coupon_id)
JOIN calendardates cd ON (cd.bc_id = bc.bc_id)
JOIN date d ON (d.date_id = cd.date_id)
GROUP BY cd.bc_id
答案 0 :(得分:0)
DISTINCT
里面没有任何意义。你想在这做什么?似乎每个不同的cd.date_id
只需要一行。
如果是这种情况,只需将cd.date_id添加到最后的GROUP BY
子句中。像这样:
GROUP BY cd.bc_id, cd.date_id
当您使用MySQL时,您不必担心在所有选定列上使用聚合函数,如果它们在由Group By子句分组的所有行中具有相同的值,如果不是MySQL将只选择第一个< / p>
<强>更新强>
查看GROUP_CONCAT的文档,您可以像这样做
GROUP_CONCAT( DISTINCT CAST(cd.date_id AS CHAR) ) As date_id