0

我一直在尝试在 SQL 中进行内部联接。但是会出现错误,例如#1248 - 每个派生表都必须有自己的别名。我已经测试了单个查询并且运行良好。任何机构都可以帮助解决这个问题吗?

这是声明:

SELECT OQT.Cuspoit_cuspoid, OQT.Cuspoit_partno, OQT.Cuspoit_qty, CQT.`Chalanit_qty ` 
FROM (
  SELECT Cuspoit.`Cuspoit_cuspoid` , Cuspoit.`Cuspoit_partno` , Cuspoit.`Cuspoit_qty` 
  FROM `Cuspoit` 
  WHERE Cuspoit.`Cuspoit_cuspoid` = 'CPO-1306023'
) AS OQT
INNER JOIN (
  SELECT CQT.`Chalanit_cuspoid` , CQT.Chalanit_partno, CQT.Chalanit_qty
  FROM (

    SELECT Chalanit_cuspoid, Chalanit_partno, SUM( `Chalanit_qty` ) AS Chalanit_qty
    FROM `Chalanits` 
    WHERE `Chalanit_cuspoid` = 'CPO-1306023'
    GROUP BY Chalanit_partno
  )
) AS CQT ON OQT.`Cuspoit_cuspoid` = CQT.`Chalanit_cuspoid `
4

1 回答 1

1

第二个子查询有一个没有别名的子查询。尝试这样的事情:

SELECT OQT.Cuspoit_cuspoid, OQT.Cuspoit_partno, OQT.Cuspoit_qty, CQT.`Chalanit_qty ` 
FROM (
  SELECT Cuspoit.`Cuspoit_cuspoid` , Cuspoit.`Cuspoit_partno` , Cuspoit.`Cuspoit_qty` 
  FROM `Cuspoit` 
  WHERE Cuspoit.`Cuspoit_cuspoid` = 'CPO-1306023'
) AS OQT
INNER JOIN (
  SELECT CQT.`Chalanit_cuspoid` , CQT.Chalanit_partno, CQT.Chalanit_qty
  FROM (

    SELECT Chalanit_cuspoid, Chalanit_partno, SUM( `Chalanit_qty` ) AS Chalanit_qty
    FROM `Chalanits` 
    WHERE `Chalanit_cuspoid` = 'CPO-1306023'
    GROUP BY Chalanit_partno
  ) cqt  --< THIS IS WHERE THE PROBLEM IS
) AS CQT ON OQT.`Cuspoit_cuspoid` = CQT.`Chalanit_cuspoid `
于 2013-06-10T17:57:29.360 回答