狂うために!!!!
アクセスで動作し、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
ありがとう
オスカー