多个地点具有相同的邮政编码会导致问题
我需要能够在此选择查询中对 Aus_Postcodes 中的邮政编码进行分组,因为发生的情况是优惠正在循环。
当前查询:
SELECT approved_business.*,
business_stores.*,
group_concat(offer ORDER BY offer ASC SEPARATOR ',') as offers,
Aus_Postcodes.state as AusState
FROM approved_business,
business_stores,
Real_Cash_Offers,
Aus_Postcodes
WHERE approved_business.id = business_stores.business_id AND
Real_Cash_Offers.business_id = approved_business.id AND
Real_Cash_Offers.storeid = business_stores.storeid AND
business_stores.postcode = Aus_Postcodes.postcode AND
approved_business.id = '1288'
GROUP BY approved_business.id
LIMIT 1
这是示例输出,我已将其编码为 JSON,因为我们的系统使用的是 JSON。
[{"id":"1288","tradingname":"Loretta Adams Bridal & Evening Wear","listed":"2012-01-26 19:26:24","pictureurl":"","business_id":"1288","storeid":"1","phone":"6139379210","street":"266 Keilor Rd","suburb":"Essendon North","state":"1","postcode":"3041","discription":"","offers":"1000|70,1000|70,1000|70,300|15,300|15,300|15,500|30,500|30,500|30","AusState":"VIC,VIC,VIC,VIC,VIC,VIC,VIC,VIC,VIC"}]
I need to be able to group the postcodes from Aus_Postcodes in this select query, as what is happening is that the offers are looping.
Current Query:
SELECT approved_business.*,
business_stores.*,
group_concat(offer ORDER BY offer ASC SEPARATOR ',') as offers,
Aus_Postcodes.state as AusState
FROM approved_business,
business_stores,
Real_Cash_Offers,
Aus_Postcodes
WHERE approved_business.id = business_stores.business_id AND
Real_Cash_Offers.business_id = approved_business.id AND
Real_Cash_Offers.storeid = business_stores.storeid AND
business_stores.postcode = Aus_Postcodes.postcode AND
approved_business.id = '1288'
GROUP BY approved_business.id
LIMIT 1
Here is the sample output, I have encoded it to JSON as that's what our system uses.
[{"id":"1288","tradingname":"Loretta Adams Bridal & Evening Wear","listed":"2012-01-26 19:26:24","pictureurl":"","business_id":"1288","storeid":"1","phone":"6139379210","street":"266 Keilor Rd","suburb":"Essendon North","state":"1","postcode":"3041","discription":"","offers":"1000|70,1000|70,1000|70,300|15,300|15,300|15,500|30,500|30,500|30","AusState":"VIC,VIC,VIC,VIC,VIC,VIC,VIC,VIC,VIC"}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
group_concat(offer ORDER BY Offer ASC SEPARATOR ',') as Offers
更改为group_concat(DISTINCT Offer ORDER BY Offer ASC SEPARATOR ',') as Offers
。Change
group_concat(offer ORDER BY offer ASC SEPARATOR ',') as offers
to begroup_concat(DISTINCT offer ORDER BY offer ASC SEPARATOR ',') as offers
.