I am developing an application that needs an embedded database, so I designed it using MYSQL, and created a SQL Statement that works in there. However, when moving to the Embedded Database (Which is Hyper-SQL (HSQLDB)) my query is not working anymore. It seems to be related to the quantity of parameters that I have on the select that must match the Group By, but if I go and add them it'll keep the data ungrouped and that doesn't work for me.
Here is the Query:
I have two tables (GFS and SUPP) with the same columns, the difference is on the behavior and that one has more populated columns that the other one.
SELECT gfs.GFSAccount, gfs.GLAccount,
CASE
WHEN gfs.ICPartner = "" THEN '[ICP_NONE]'
WHEN gfs.ICPartner <> "" THEN gfs.ICPartner
END AS ICPartner,
CASE
WHEN gfs.PPESupplementalData <> '' THEN gfs.PPESupplementalData
WHEN gfs.PPESupplementalData = '' THEN '[NONE]'
END AS SupplementalData,
CASE
WHEN gfs.AccountType = 'SALES AND COS' THEN gfs.PCode
WHEN gfs.AccountType = 'COO' THEN 'COO'
WHEN gfs.AccountType = 'OTHERS' THEN gfs.Business
END AS Business,
Round(Sum(gfs.Amount), 2) AS Amount
FROM gfs, supp
WHERE gfs.GLAccount <> supp.GLAccount
GROUP BY gfs.GFSAccount,
CASE WHEN gfs.ICPartnerSplit = 1 THEN gfs.ICPartner END
UNION
SELECT GFSAccount, GLAccount,
CASE
WHEN ICPartner = "" THEN '[ICP_NONE]'
WHEN ICPartner <> "" THEN ICPartner
END AS ICPartner,
CASE
WHEN SuppData <> '' THEN SuppData
WHEN SuppData = '' THEN '[NONE]'
END AS SupplementalData,
Business, Round(Sum(Amount), 2) AS Amount
FROM supp
ORDER BY GFSAccount;
There're a lot of conversions for blank and fixed fields, but the main issue is with the 3 group by (2 within every select, and one in the very end), that it's not allowing me to do it.
(I know that the query itself isn't the best created or optimized, but I've been out from databases for a while and I'm kind of rusty)
Is there any suggestions you guys can do to me in order to make it work in HSQLDB (Or another database that is not MySQL)??