次のようなクエリがあります。
SELECT
t.type,
SUM( t.external_account )
FROM
u_contracts c,
u_data u,
u_transactions t
WHERE
c.user_id = u.id
AND t.contract_id = c.id
AND t.nulled =0
AND DATE (c.init_date) < DATE (u.dead)
AND u.dead IS NOT NULL
AND t.type != 'repay'
GROUP BY
t.type;
これで目的の結果が得られましたが、次のような特定のフィールド名で ORDER BY を追加したいと思います。
ORDER BY FIELD( t.type, 'type1', 'type2', ... )
しかし、それをクエリに挿入することはできません。私がこのようにしようとすると:
SELECT
t.type,
SUM( t.external_account )
FROM
u_contracts c,
u_data u,
u_transactions t
WHERE
c.user_id = u.id
AND t.contract_id = c.id
AND t.nulled =0
AND DATE (c.init_date) < DATE (u.dead)
AND u.dead IS NOT NULL
AND t.type != 'repay'
ORDER BY
FIELD( t.type, 'initial', 'commision', 'overpay', 'penalty', 'penalty2' )
GROUP BY
t.type;
それは私のSQLエラーを与えます:
ERROR 1064 (42000): 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 'GROUP BY t.type' at line 17
これを行う適切な方法は何ですか?