次のクエリを検討してください。
SELECT x.* FROM
(
(
SELECT (id,
insertuserid AS transaction_user_id,
(user_price * (-1)) AS amount,
"INVOICE" AS transaction_type,
insertdatetime
)
FROM invoice
WHERE transaction_user_id = 4
)
UNION
(
SELECT (id,
user_id AS transaction_user_id,
amount,
"PAYMENT" AS transaction_type,
insertdatetime)
FROM payment
WHERE user_id = 4
)
)
AS x
ORDER BY x.insertdatetime
AS
最初に見たときのクエリエラー。
Unionの最初のに変更insertuserid AS transaction_user_id
しても、次の行にある 2 番目の行でエラーになります: !!!insertuserid
SELECT
AS
(user_price * (-1)) AS amount
エラーメッセージ:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'AS transaction_user_id, (user_price * (-1)) AS amount, "' at line 5
SELECT x.* FROM ( ( SELECT (id, insertuserid AS transaction_user_id,
(user_price * (-1)) AS amount, "INVOICE" AS transaction_type, insertdatetime )
FROM invoice WHERE transaction_user_id = 4 ) UNION
( SELECT (id, user_id AS transaction_user_id, amount,
"PAYMENT" AS transaction_type, insertdatetime) FROM payment
WHERE user_id = 4 ) ) AS x
ORDER BY x.insertdatetime
ありがとうございました