多个地点具有相同的邮政编码会导致问题

发布于 2025-01-03 02:55:08 字数 1160 浏览 1 评论 0原文

我需要能够在此选择查询中对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花想c 2025-01-10 02:55:08

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 be group_concat(DISTINCT offer ORDER BY offer ASC SEPARATOR ',') as offers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文