使用3个不同的变量

时间:2015-11-07 11:36:25

标签: mysql

我一直想要的是根据3个不同的变量来定价:brand_idmodel_idmotor_id

我正在使用的表格的设计:

My app model

唯一的问题是当我为databaseapp_lkp_prices添加INNER JOIN时,我得到零结果集(fyi,当前没有设置任何价格,因此databaseapp_lkp_prices是一个空表)

当我没有添加NULL INNER JOIN

时,我希望看到price代替databaseapp_lkp_prices代替48,000条记录

我的查询是:

SELECT
a.brand,
b.model,
c.motor,
d.ecu_hardware_ver,
d.ecu_software_ver,
d.ecu_software_upg_ver,
d.ecu_brand,
d.ecu_type,
d.eprom,
d.eprom_desc,
d.`checksum`,
d.checksum16,
c.motor_hp * 1.2 AS motor_hp,
e.price,
c.motor_id,
c.model_id,
c.brand_id
FROM
databaseapp_brand AS a
INNER JOIN databaseapp_model AS b ON b.brand_id = a.brand_id
INNER JOIN databaseapp_motor AS c ON b.model_id = c.model_id
INNER JOIN databaseapp_ecu AS d ON d.motor_id = c.motor_id
INNER JOIN databaseapp_lkp_prices AS e ON c.brand_id = e.brand_id AND c.model_id = e.model_id AND c.motor_id = e.motor_id
ORDER BY
a.brand ASC,
b.model ASC

任何人都能够帮助我解决为什么在我试图查看价格时我得到的结果为零。

干杯!

1 个答案:

答案 0 :(得分:1)

内部联接需要匹配。没有比赛没有排。对于databaseapp_lkp_prices贡献,您应该尝试LEFT JOIN而不是INNER JOIN。