gpt4 book ai didi

PHP Mysql 选择查询来排序对

转载 作者:行者123 更新时间:2023-11-29 19:34:21 25 4
gpt4 key购买 nike

我正在为舞蹈学校制作客户数据库应用程序。

我需要显示参与同一舞蹈级别的所有客户的概览。但我想要的是情侣的概览订单,而不是客户 ID 的订单。为此,我要连接三个表(请查看下面的查询)每个客户在 CRM_CONTACTS 表中都有一个唯一的 ID,并且在该行中还有对其合作伙伴 (PARTNER_ID) 的引用。

表 CRM_CONTACTS

ID   CONTACTS_LNAME
1 VON KLOMPENBURG
2 Mc Donalds
3 MC Adams
4 Mr X

然后我就有了 CRM_PRODUCTS ID PRODUCTS_NAME
1 初学者 2 中间体 3进阶

然后是我为联系人分配产品/级别并指出他/她的合作伙伴的表格

ID   CONTACTS_ID    PRODUCTS_ID   PARTNER_ID
1 1 1 4
2 2 1 3
3 3 1 2
4 4 1 1

现在我想收到基于parter_id的情侣列表订单所以对于初学者水平我会得到这样的列表1 冯·克隆彭堡2 X先生3 麦当劳4 麦克亚当斯

这是我的选择语句

 $result = mysqli_query($coni,"SELECT CRM_PRODUCTS_PURCHASE.ID, CONTACTS_ID, 
CRM_PRODUCTS.PRODUCTS_NAME,
CRM_PRODUCTS.PRODUCTS_PRICE,CRM_PRODUCTS_PURCHASE.PARTNER_ID,
CRM_PRODUCTS_PURCHASE.PARTNER_NAME,
PRODUCTS_PURCHASE_REMARKS,PRODUCTS_PURCHASE_DISCOUNT,
PRODUCTS_PURCHASE_PAIDBYBANK,PRODUCTS_PURCHASE_PAIDBYCASH,
CRM_CONTACTS.CONTACTS_LNAME, CRM_CONTACTS.CONTACTS_FNAME
FROM CRM_PRODUCTS_PURCHASE
LEFT JOIN CRM_CONTACTS ON CRM_PRODUCTS_PURCHASE.CONTACTS_ID = CRM_CONTACTS.ID
LEFT JOIN CRM_PRODUCTS ON CRM_PRODUCTS_PURCHASE.PRODUCTS_ID = CRM_PRODUCTS.ID
WHERE CRM_PRODUCTS_PURCHASE.PRODUCTS_ID = '". $PRODUCTS_ID . "'");

最佳答案

你可以这样做:

$result = mysqli_query($coni,"SELECT CRM_PRODUCTS_PURCHASE.ID, CONTACTS_ID, 
CRM_PRODUCTS.PRODUCTS_NAME,
CRM_PRODUCTS.PRODUCTS_PRICE,CRM_PRODUCTS_PURCHASE.PARTNER_ID,
CRM_PRODUCTS_PURCHASE.PARTNER_NAME,
PRODUCTS_PURCHASE_REMARKS,PRODUCTS_PURCHASE_DISCOUNT,
PRODUCTS_PURCHASE_PAIDBYBANK,PRODUCTS_PURCHASE_PAIDBYCASH,

CRM_CONTACTS.CONTACTS_LNAME, CRM_CONTACTS.CONTACTS_FNAME
FROM CRM_PRODUCTS_PURCHASE
LEFT JOIN CRM_CONTACTS ON CRM_PRODUCTS_PURCHASE.CONTACTS_ID = CRM_CONTACTS.ID
LEFT JOIN CRM_PRODUCTS ON CRM_PRODUCTS_PURCHASE.PRODUCTS_ID = CRM_PRODUCTS.ID
WHERE CRM_PRODUCTS_PURCHASE.PRODUCTS_ID = '". $PRODUCTS_ID . "'
ORDER BY IF (ID < PARTNER_ID, ID, PARTNER_ID)");

您的顾客将成对订购。

关于PHP Mysql 选择查询来排序对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41616151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com