复杂的查询 - 需要帮助!

发布于 2024-08-14 17:46:49 字数 1893 浏览 13 评论 0原文

真的希望有人能帮助我解决这个问题! 我有 6 个表:

产品
prodid

Prodequipment
产品
装备类主要
equipclassor

装备类别
classid

装备功能
装备
classid

设备
equipid

车间设备
workshopid
equipid

产品 – 一些产品的列表
设备 – 一些设备的列表
Prodequipment – 列出生产产品所需的设备。您可以使用equipclassmain中列出的设备或将其替换为equipclassor中的设备。表Products 与表Prodequipment 具有一对多关系,即您将使用许多不同的工具(设备)来生产一种产品,但您可以选择使用equipclassmain/equipclassor 对中的任何一个。例如,要给照片加框,您可以使用木框或塑料框(一对)和盖玻璃或盖塑料(第二对)。您可以根据需要组合它,但两对都应该使用:木框架加盖玻璃或塑料框架加盖玻璃或木框架加塑料盖或塑料框架加塑料盖。
设备功能设备类别 – 由于一件设备可以以不同的方式使用,因此它不直接链接到表 Prodequipment。我创建了 Equipclasses 表,其中列出了每种可能设备的所有单一用途,并创建了 Equipfunctions 表,其中列出了每种设备的单一用途。
车间设备 - 列出他们正在使用的车间和设备。

现在我需要一个可以由两个不同的给定车间制造的产品列表(假设workshopid = 1和workshopid = 4),即这两个车间都拥有生产这些产品所需的所有设备。请记住,这些车间不必使用与我上面描述的相同的设备来执行此操作。

我正在尝试执行此查询:

SELECT prodid FROM Products JOIN (
    SELECT workshopid, prodlist, equipclassmain, equipclassor, 
        if( LOCATE( equipclassmain, prodlist ) >0 
            AND LOCATE( equipclassor, prodlist ) >0, 1, 0 ) AS pairstatus FROM Prodequipment JOIN
    (
        SELECT classid FROM Equipclasses JOIN (
            SELECT classid FROM Equipfunctions JOIN (
                SELECT workshopid, GROUP_CONCAT( equipid ) AS prodlist FROM Workshopequipment 
                    GROUP BY workshopid
            ) 
            equipfunclist GROUP BY equipid 
        ) equipclasslist GROUP BY classid
    ) WorkshopequipmentList HAVING pairstatus = 1 AND workshopid in (1, 4)
) prodbyworkshops ON classid = equipclassmain OR classid = equipclassor

但我收到“字段列表中的列 classid 不明确”。知道这里出了什么问题吗?

谢谢你!

really hope someone can help me on this one!
I have 6 tables:

Products

prodid

Prodequipment

prodid

equipclassmain

equipclassor

Equipclasses

classid

Equipfunctions

equipid

classid

Equipment

equipid

Workshopequipment

workshopid

equipid

Products – a list of some products

Equipment – a list of some equipment

Prodequipment – lists what equipment is needed to do a product. You can use equipment listed in equipclassmain or replace it by equipment in equipclassor. Table Products has one to many relation to table Prodequipment, i.e. you will use many different tools (equipment) to produce one product, but you can choose to use anyone in the pair equipclassmain/equipclassor. For instance to frame a photo you can use a wooden frame or plastic frame (one pair) and a cover glass or cover plastic (second pair). You can combine it as you wish, but both pairs should be used: wooden frame with cover glass or plastic frame with cover glass or wooden frame with plastic cover or plastic frame with plastic cover.

Equipfunctions and Equipclasses – Because one piece of equipment can be used in different ways it is not linked directly to table Prodequipment. I have created table Equipclasses where all single use of every possible equipment is listed and table Equipfunctions where I list those single uses for every equipment.

Workshopequipment – lists workshops and equipment they are using.

Now I need a list of products which can be manufactured by two different given workshops (let's say workshopid = 1 and workshopid = 4), i.e. both those workshops have all equipment needed to produce those products. Bear in mind that those workhops don't have to use the same equipment to do so as I described above.

I'm trying with this query:

SELECT prodid FROM Products JOIN (
    SELECT workshopid, prodlist, equipclassmain, equipclassor, 
        if( LOCATE( equipclassmain, prodlist ) >0 
            AND LOCATE( equipclassor, prodlist ) >0, 1, 0 ) AS pairstatus FROM Prodequipment JOIN
    (
        SELECT classid FROM Equipclasses JOIN (
            SELECT classid FROM Equipfunctions JOIN (
                SELECT workshopid, GROUP_CONCAT( equipid ) AS prodlist FROM Workshopequipment 
                    GROUP BY workshopid
            ) 
            equipfunclist GROUP BY equipid 
        ) equipclasslist GROUP BY classid
    ) WorkshopequipmentList HAVING pairstatus = 1 AND workshopid in (1, 4)
) prodbyworkshops ON classid = equipclassmain OR classid = equipclassor

But I get an "Column classid in field list is ambiguous". Any idea what's wrong here?

THANK YOU!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泛滥成性 2024-08-21 17:46:49

您的查询引用了多个具有 classid 列的表。
因此,当您在 HAVING 子句中引用 classid 时,它不知道要获取哪个表的 classid

您需要编写tablename.classid,其中tablename是包含classid列的表的名称。 (可能是equipclasslist;我没有查看查询)

Your query references multiple tables that have a classid column.
Therefore, when you reference classid in the HAVING clause, it doesn't know which table to get the classid for.

You need to write tablename.classid where tablename is the name of the table containing the classid column. (Probably equipclasslist; I didn't look at the query)

从此见与不见 2024-08-21 17:46:49

它来自查询的部分:

...
SELECT classid 
FROM Equipclasses JOIN (
    SELECT classid
    FROM Equipfunctions...

EquipClasses 和内部查询都有一个 classId。您需要指定您要选择的内容。

It's from the part of the query with:

...
SELECT classid 
FROM Equipclasses JOIN (
    SELECT classid
    FROM Equipfunctions...

Both EquipClasses and the inner query have a classId. You need to specify which you're selecting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文