Php mysql数据库表中的混淆
我对将结果放入两个表格有点困惑,我知道这很简单,但没有得到任何线索。。 这是我的查询,它给出了结果,但当我使用Php mysql数据库表中的混淆,php,mysql,Php,Mysql,我对将结果放入两个表格有点困惑,我知道这很简单,但没有得到任何线索。。 这是我的查询,它给出了结果,但当我使用group by时,它只给出了一行的结果,即使数据库中的实际结果是(300500),因为我是通过两个表中常见的lead_id获取结果 SELECT inv.amount, crmd.computers, crmd.product_id, crmd.pc_opti FROM invoice AS inv, lead_crm_data AS crmd WHERE inv.lead_id =
group by
时,它只给出了一行的结果,即使数据库中的实际结果是(300500),因为我是通过两个表中常见的lead_id
获取结果
SELECT inv.amount, crmd.computers, crmd.product_id, crmd.pc_opti
FROM invoice AS inv, lead_crm_data AS crmd
WHERE inv.lead_id = '310'
AND crmd.lead_id = '310'
GROUP BY inv.lead_id
下面是给定查询的结果
amount computers product_id pc_opti
300 2 7, 6 2
300 3 7, 6 3
540 2 7, 6 2
540 3 7, 6 3
结果为分组依据
300 2 7, 6 2
期望的结果
300 2 7, 6 2
540 3 7, 6 3
试试这个:
SELECT inv.amount, crmd.computers, crmd.product_id, crmd.pc_opti
FROM invoice AS inv, lead_crm_data AS crmd
WHERE inv.lead_id = '310'
AND crmd.lead_id = '310'
GROUP BY inv.amount
您可以使用更好的(IMHO)语法:
你在分组条件中使用的字段是什么?@Til86
lead\u id
因为lead id是两个表中的公共字段。你能用group by命令编写编码吗?结果是什么?你确定你知道用什么方法分组吗?您希望通过此查询实现什么?请向我们展示您想要的结果…@jogesh\u p:因为lead\u id已经是“310”,所以当您分组时,您只会得到一条记录!!当lead_id为310时,您希望每个“金额”有一个不同的记录。。。我的查询也是如此:):)非常感谢,我也尝试了内部连接
,但始终没有得到想要的结果,,+1表示澄清,以及其他选项:)
SELECT inv.amount, crmd.computers, crmd.product_id, crmd.pc_opti
FROM invoice AS inv INNER JOIN lead_crm_data AS crmd
ON inv.lead_id = crmd.lead_id
AND inv.lead_id = '310'
GROUP BY inv.amount