0

我有以下模型:

在此处输入图像描述

我已经有一段时间了,但仍然不知道如何正确解决它。已经考虑加入两个别名子查询,加入两个视图,并尝试了一个庞大而丑陋的一体式查询,但都没有奏效。

我的问题很简单:

如何选择 deivce_names.name 并将它们与型号和制造商匹配?

4

3 回答 3

1
SELECT
    name, manufacturer, model
FROM
    device_names
    JOIN devices ON (device_names.id = name_id)
    JOIN devices_generic ON (generic_device_id = devices_generic.id)
    JOIN device_manufacturers ON (manufacturer_id = device_manufacturers.id)
    JOIN device_models ON (model_id = device_models.id)
于 2013-03-04T03:41:18.847 回答
0
select
    device_names.name as device_name,
    device_manufacturers.name as device_manufacturer_name,
    device_models.name as device_model_name
from deivce_names
join device on device.name_id = deivce_names.id
join devices_generic on devices_generic.id = devices.generic_device_id
join device_manufacturers on devices_generic.manufacturer_id = device_manufacturers.id
join device_models on device_models.id = devices_generic.model_id
于 2013-03-04T03:43:42.150 回答
0

SELECT dm1.manufacturer, dm2.model from device_manufacturers as dm1 join devices_generic as dg on dg.manufacturer_id = dm1.id join device_models as dm2 on dm2.id = dg.model_id join devices as d2 on d2.generic_device_id = dg.id join device_names as dn on dn.id = d2.name_id where name = 'foo'

将来,您可能只想简单地将数据放入小提琴中并在那里使用它。

于 2013-03-04T03:50:53.987 回答