1

Oracle SQL でエラーが発生しました: ORA- 01427単一行のサブクエリが複数の行 を返します
その場所。

これが私のテーブルです

VID          MILEAGE         LOCATION        VSIZE        TRANSMISSION
----------------------------------------------------------------------
V-101       70               AHMD            COMPACT      AUTOMATIC
V-102       50               SURAT           COMPACT      AUTOMATIC
V-103       10               AHMD            MID-SIZE     MANUAL
V-104       30               AHMD            MID-SIZE     AUTOMATIC
V-105       15               VADODARA        FULL-SIZE    AUTOMATIC
V-106       20               AHMD            LUXURY       AUTOMATIC
V-107       50               AHMD            LUXURY       MANUAL

そして、これは私のクエリです:

SELECT location, transmission, mileage FROM vehicles_workshop 
  WHERE transmission = 'MANUAL' AND mileage = 
      ( SELECT DISTINCT mileage FROM vehicles_workshop WHERE mileage < 
          (SELECT MAX(mileage) FROM vehicles_workshop WHERE vsize = 'LUXURY')
      );
4

2 に答える 2

0

INサブクエリの前に equal to 演算子を使用する代わりに

SELECT location, transmission, mileage FROM vehicles_workshop 
  WHERE transmission = 'MANUAL' AND mileage IN
      ( SELECT DISTINCT mileage FROM vehicles_workshop WHERE mileage < 
          (SELECT MAX(mileage) FROM vehicles_workshop WHERE vsize = 'LUXURY')
      );

マイレージを比較するためのサブクエリは複数の値を返しますが、 equal to 演算子は単一の値のみを比較するために機能するため、エラーがスローされます。

于 2014-07-22T07:51:43.933 に答える
0
SELECT location, transmission, mileage 
FROM vehicles_workshop t1
WHERE transmission = 'MANUAL'         --manual transmission
  AND EXISTS
      ( SELECT *
        FROM vehicles_workshop t2 
        WHERE vsize = 'LUXURY'        --luxury vehicle
        AND t2.location = t1.location --same location
        AND t2.mileage  > t1.mileage) --higher mileage
      ;
于 2014-07-22T07:59:12.297 に答える