联合查询中的排序错误

发布于 2024-09-08 03:14:02 字数 1537 浏览 7 评论 0原文

SELECT DISTINCT rt . d_rev_id , rt . d_rev_code , rt . d_reason , rt . d_rev_status , rt . d_apb , rt . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , rt . d_part_name , rt . d_part_desc , rt . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , rt . d_projectid , rt . d_abd , rt . d_apbd 
FROM 
    ( 
        ( 
        design_parts pt 
        INNER JOIN design_part_number_val pnv 
        USING ( d_partid ) 
        INNER JOIN design_revision_temp rt 
        USING ( d_partid ) 
        ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
    )
WHERE rt . d_projectid = 1 
AND 1 
GROUP BY d_rev_id 
UNION ALL 
SELECT DISTINCT dr . d_rev_id , dr . d_rev_code , dr . d_reason , dr . d_part_name , dr . d_apb , dr . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , dr . d_part_name , dr . d_part_desc , dr . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , dr . d_projectid , dr . d_apbd , dr . d_cbd 
FROM 
    ( 
        ( 
        design_parts pt 
        INNER JOIN design_part_number_val pnv 
        USING ( d_partid ) 
        INNER JOIN design_revision dr 
        USING ( d_partid ) 
        ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
    ) 
WHERE dr . d_projectid = 1 
AND 1 
GROUP BY d_partid  
ORDER BY `rt.d_abd` ASC

当我对所选字段进行排序时,此查询出了什么问题。我收到错误“#1054 - “订单子句”中的未知列“rt.d_abd””。 请帮我

SELECT DISTINCT rt . d_rev_id , rt . d_rev_code , rt . d_reason , rt . d_rev_status , rt . d_apb , rt . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , rt . d_part_name , rt . d_part_desc , rt . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , rt . d_projectid , rt . d_abd , rt . d_apbd 
FROM 
    ( 
        ( 
        design_parts pt 
        INNER JOIN design_part_number_val pnv 
        USING ( d_partid ) 
        INNER JOIN design_revision_temp rt 
        USING ( d_partid ) 
        ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
    )
WHERE rt . d_projectid = 1 
AND 1 
GROUP BY d_rev_id 
UNION ALL 
SELECT DISTINCT dr . d_rev_id , dr . d_rev_code , dr . d_reason , dr . d_part_name , dr . d_apb , dr . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , dr . d_part_name , dr . d_part_desc , dr . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , dr . d_projectid , dr . d_apbd , dr . d_cbd 
FROM 
    ( 
        ( 
        design_parts pt 
        INNER JOIN design_part_number_val pnv 
        USING ( d_partid ) 
        INNER JOIN design_revision dr 
        USING ( d_partid ) 
        ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
    ) 
WHERE dr . d_projectid = 1 
AND 1 
GROUP BY d_partid  
ORDER BY `rt.d_abd` ASC

What is wrong in this query as I ordering the field that are selected. I am getting an Error "#1054 - Unknown column 'rt.d_abd' in 'order clause' ".
Please help me

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

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

发布评论

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

评论(3

谎言月老 2024-09-15 03:14:02

错误在于您将 tablename.columnname 放在反引号之间:MySQL 将其解释为一个列名。

要么使用“表名”。“列名”,要么根本不使用反引号。

The error is that you put tablename.columnname between backticks: MySQL interprets that as one columnname.

Either use `tablename`.`columnname` or no backticks at all.

稳稳的幸福 2024-09-15 03:14:02
ORDER BY `rt.d_abd` ASC

应该是

ORDER BY `rt`.`d_abd` ASC

ORDER BY rt.d_abd ASC

已编辑
您可以使用单引号也可以工作

ORDER BY 'rt.d_abd' ASC

我认为您没有使用正确的语法使用 () 正确

应该如下

(SELECT column1. column2
FROM table1)
UNION ALL
(SELECT column3, column4
FROM table2)
ORDER BY column1
ORDER BY `rt.d_abd` ASC

should be

ORDER BY `rt`.`d_abd` ASC

or

ORDER BY rt.d_abd ASC

EDITED
you can use single quotes also work

ORDER BY 'rt.d_abd' ASC

I think you are not using proper syntax use ( and ) properly

it should as follow

(SELECT column1. column2
FROM table1)
UNION ALL
(SELECT column3, column4
FROM table2)
ORDER BY column1
玩世 2024-09-15 03:14:02

尝试这个查询:

(SELECT DISTINCT rt . d_rev_id , rt . d_rev_code , rt . d_reason , rt . d_rev_status , rt . d_apb , rt . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , rt . d_part_name , rt . d_part_desc , rt . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , rt . d_projectid , rt . d_abd , rt . d_apbd 
FROM 
    design_parts pt 
    INNER JOIN design_part_number_val pnv 
    USING ( d_partid ) 
    INNER JOIN design_revision_temp rt 
    USING ( d_partid ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
WHERE rt . d_projectid = 1 
GROUP BY d_rev_id)
UNION ALL 
(SELECT DISTINCT dr . d_rev_id , dr . d_rev_code , dr . d_reason , dr . d_part_name , dr . d_apb , dr . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , dr . d_part_name , dr . d_part_desc , dr . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , dr . d_projectid , dr . d_apbd , dr . d_cbd 
FROM 
    design_parts pt 
    INNER JOIN design_part_number_val pnv 
    USING ( d_partid ) 
    INNER JOIN design_revision dr 
    USING ( d_partid ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
WHERE dr . d_projectid = 1 
GROUP BY d_partid)
ORDER BY `d_abd` ASC

Try this query:

(SELECT DISTINCT rt . d_rev_id , rt . d_rev_code , rt . d_reason , rt . d_rev_status , rt . d_apb , rt . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , rt . d_part_name , rt . d_part_desc , rt . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , rt . d_projectid , rt . d_abd , rt . d_apbd 
FROM 
    design_parts pt 
    INNER JOIN design_part_number_val pnv 
    USING ( d_partid ) 
    INNER JOIN design_revision_temp rt 
    USING ( d_partid ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
WHERE rt . d_projectid = 1 
GROUP BY d_rev_id)
UNION ALL 
(SELECT DISTINCT dr . d_rev_id , dr . d_rev_code , dr . d_reason , dr . d_part_name , dr . d_apb , dr . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , dr . d_part_name , dr . d_part_desc , dr . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , dr . d_projectid , dr . d_apbd , dr . d_cbd 
FROM 
    design_parts pt 
    INNER JOIN design_part_number_val pnv 
    USING ( d_partid ) 
    INNER JOIN design_revision dr 
    USING ( d_partid ) 
    LEFT JOIN design_pn_custom_field_options cfv 
    ON d_optionvalue = d_pn_val 
WHERE dr . d_projectid = 1 
GROUP BY d_partid)
ORDER BY `d_abd` ASC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文