选择操作期间列名错误

时间:2018-07-23 17:20:08

标签: mysql sql database

我遇到以下错误:

  

信息209,级别16,状态1,第3行,列名称“ NUM_0”不明确。

SELECT BPR_0, BPAPAY_0, BPYNAM_0, BPYADDLIG_0, NUM_0 -- and so on
  FROM PROD.SINVOICE, PROD.SINVOICED
  WHERE SINVOICE.NUM_0 = SINVOICED.NUM_0

enter image description here

3 个答案:

答案 0 :(得分:1)

使用表alise明确限定列名:

select sin.col, . . ., sind.col, . . ., c.col, . . .
from prod.sininvoice sin inner join
     prod.sininvoiced sind
     on sind.num_0 = sin_num_0 inner join
     prod.customer c 
     on . . .;

答案 1 :(得分:0)

由于SINVOICE和SINVOICED表中都存在“ NUM_0”列,因此您需要使用别名来指定该列。
例如,您选择select语句中的SINVOICE.NUM_O或SINVOICED.NUM_O取决于要从哪个表中此列值。

答案 2 :(得分:0)

正确使用Alias

示例

SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID;

针对您的情况

select t1.col1,t1.col2 ....t1.coln from yourtable t1
inner join yourtable t2 on t1.num0=t2.num0