0

I'm trying to get pairs of matching columns by joining the table Customer with the already joined table of BuyVehicle & Vehicle which I've given the alias 't'. How is p1.SSN and I assume p2.SSN will follow an unknown column if I've assigned the alias in the first line?

SELECT p1.SSN, p2.SSN FROM Customer AS p1, Customer AS p2 
INNER JOIN (SELECT BVSSN, BVVin, Vin FROM CarPurchase INNER JOIN Car ON BVVin = Vin) 
AS t ON p1.SSN = BVSSN & p2.SSN = BVSSN
WHERE p1.SSN < p2.SSN AND //matching columns comparisons yet to be added;

ERROR 1054 (42S22): Unknown column 'p1.SSN' in 'on clause'

4

2 に答える 2

2

問題は、さまざまなタイプの結合が混在していることです。p1 テーブルは「結合」の一部ではないため、MySQL は p1 テーブルを認識しません。以下はこれを修正する必要があります。

SELECT p1.SSN, p2.SSN
FROM Customer AS p1 cross join
     Customer AS p2 INNER JOIN
     (SELECT BVSSN, BVVin, Vin
      FROM CarPurchase INNER JOIN
           Car
           ON BVVin = Vin
    ) AS t
    ON p1.SSN = BVSSN and p2.SSN = BVSSN
WHERE p1.SSN < p2.SSN AND //matching columns comparisons yet to be added;

WHERE実際には、句を句に移動するだけですON

SELECT p1.SSN, p2.SSN
FROM Customer AS p1 join
     Customer AS p2 
     on  p1.SSN < p2.SS INNER JOIN
     (SELECT BVSSN, BVVin, Vin
      FROM CarPurchase INNER JOIN
           Car
           ON BVVin = Vin
    ) AS t
    ON p1.SSN = BVSSN and p2.SSN = BVSSN
于 2012-10-08T01:12:31.273 に答える
0
  1. &とは-そのようなSQLはありません..ANDに変更
  2. これは正しくありませんSELECTBVSSN、BVVin、Vin FROM CarPurchase INNER JOIN Car ON BVVin = Vin

    CarPurchase.BVSSN、Car.BVVin、Car.VinをCarPurchaseから選択します。CarPurchaseの内部に参加します。CarPurchase.BVVin= Car.Vin

それ以外の場合はアリスを使用します

于 2012-10-07T23:45:10.350 に答える