0

狂うために!!!!

アクセスで動作し、MySQL では望ましくありません。そして、私はここの投稿でトリックを取ります。

ここでクエリ:

SELECT A.B_ID,
       B.CNT_B,
       B.MAX_PRICE,
       B.SUM_AB,
       B.SUM_C_AB,
       B.UNIQUE_B,
       B.Costi,
       B.COUNTDOWN,
       A.AUCT_ID
FROM MONITOR AS A
INNER JOIN
  (SELECT B_ID,
          COUNT(B_ID) AS CNT_B,
          MAX(PREZZO_ATTUALE) AS MAX_PRICE,
          SUM(TOT_PUNT_AB) AS SUM_AB,
          SUM(TOT_CAMBI_AB) AS SUM_C_AB,
          (CNT_B-SUM_AB) AS UNIQUE_B,
          (0.035*3*CNT_B+MAX_PRICE) AS COSTI,
          45-SUM(CONT_PROVV_AB) AS COUNTDOWN
   FROM MONITOR
   WHERE AUCT_ID = '123456789'
   GROUP BY B_ID) AS B
  ON A.B_ID= B.B_ID
WHERE A.AUCT_ID = '123456789'
ORDER BY B.MAX_PRICE DESC,
         B.CNT_B DESC

ショー

エラー: [MySQL][ODBC 3.51 ドライバー][mysqld-5.5.33-31.1-log]「フィールド リスト」の不明な列「CNT_B」

CNT_B を離れると、MAX_PRICE などが表示されます。

私は確信しています。それはINNER JOINの呪いです!

ここでエラーのフィドル


解決

同じサブクエリ内で ALIAS 値を使用できません。

したがって、新しい VALID クエリは次のとおりです。

   SELECT A.B_ID,
           B.CNT_B,
           B.MAX_PRICE,
           B.SUM_AB,
           B.SUM_C_AB,
           B.UNIQUE_B,
           B.Costi,
           B.COUNTDOWN,
           A.AUCT_ID
    FROM MONITOR AS A
    INNER JOIN
      (SELECT B_ID,
              COUNT(B_ID) AS CNT_B,
              MAX(PREZZO_ATTUALE) AS MAX_PRICE,
              SUM(TOT_PUNT_AB) AS SUM_AB,
              SUM(TOT_CAMBI_AB) AS SUM_C_AB,
              (COUNT(B_ID)-SUM(TOT_PUNT_AB)) AS UNIQUE_B,
              (0.035*3*COUNT(B_ID)+MAX(PREZZO_ATTUALE)) AS COSTI,
              45-SUM(CONT_PROVV_AB) AS COUNTDOWN
       FROM MONITOR
       WHERE AUCT_ID = '123456789'
       GROUP BY B_ID) AS B
      ON A.B_ID= B.B_ID
    WHERE A.AUCT_ID = '123456789'
    ORDER BY B.MAX_PRICE DESC,
             B.CNT_B DESC

SQL FIDDLE

ありがとう

オスカー

4

2 に答える 2

1

次のサブクエリからメインに移動します。

 (CNT_B-SUM_AB) AS UNIQUE_B,
 (0.035*3*CNT_B+MAX_PRICE) AS COSTI,

関数からエイリアスを単独で呼び出そうとしているためです。Computed Aggregate

あなたがこれを持っているように:

SELECT A.B_ID,
   B.CNT_B,
   B.MAX_PRICE,
   B.SUM_AB,
   B.SUM_C_AB,
   B.CNT_B-B.SUM_AB AS UNIQUE_B,
   (0.035*3*B.CNT_B+B.MAX_PRICE) AS COSTI,
   B.COUNTDOWN,
   A.AUCT_ID
FROM MONITOR A
INNER JOIN
 (SELECT B_ID,
      COUNT(B_ID) AS CNT_B,
      MAX(PREZZO_ATTUALE) AS MAX_PRICE,
      SUM(TOT_PUNT_AB) AS SUM_AB,
      SUM(TOT_CAMBI_AB) AS SUM_C_AB,
      45-SUM(CONT_PROVV_AB) AS COUNTDOWN
FROM MONITOR
WHERE AUCT_ID = '3453015'
GROUP BY B_ID) B
ON A.B_ID= B.B_ID
WHERE A.AUCT_ID = '3453015'
ORDER BY B.MAX_PRICE DESC,
     B.CNT_B DESC

SQLFiddleを参照してください

于 2013-11-04T01:40:26.317 に答える