我有点混淆将结果导入两个表,我知道这很简单,但没有得到任何线索..
这是我的查询给我结果,但是当我使用group by
时,它只是给我一行的结果,即使数据库中的实际结果是(300,500)因为我通过以下方式获取结果两个表中常见的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
GROUP BY
的结果300 2 7, 6 2
渴望REsult
300 2 7, 6 2
540 3 7, 6 3
答案 0 :(得分:1)
试试这个:
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
您可以使用更好的(恕我直言)语法:
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