1
このselectステートメントにif else条件を設定しようとしています。 customerID
またはaccountID
をこのマッパーに渡しているので、どちらが渡されているかを確認する必要があります。 customerId
が存在しない(したがってaccountId
が渡された)最初のケースがあったため、内部結合が実行されました。第2のものは、accountID
が存在しない(したがってcustomerId
を通過した)ときである。その後、ケースの終わりに、日付を降順に並べ替えたいと思います。SELECT内でケースを使用するとSQL構文エラーが発生する
SELECT i.invoice_id, i.account_id, total_amount_due, due_date, bp.eff_date, bp.end_date, total_amount_due
(
CASE
WHEN customerId = null
THEN INNER JOIN server.bill_periods bp ON bp.invoice_id = i.invoice_id
WHERE account_id=#{accountId}
ELSE INNER JOIN server.bill_periods bp ON bp.invoice_id = i.invoice_id
INNER JOIN server.cust_acct_rel car ON car.account_id = i.account_id
WHERE car.customer_id=#{customerId}
END)
ORDER BY end_date DESC
ただし、これを実行すると、このエラーが発生します。
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.sql.SQLSyntaxErrorException: 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 'INNER JOIN server.bill_periods bp ON bp.invoice_id = i.invoice_id WHERE ' at line 5
私がここで間違っていることを知っている人はいますか?
あなたのコードでは、意味がありません。例えば、 'FROM'節はありません。 –
https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-クエリ – Strawberry
おそらくケースステートメント上のテーブルを結合する新しい構造体 – maSTAShuFu