Libre: 7.1.8.1
Windows 10
HSQLDB Embedded
Hello, I’m new to Libre Base and SQL. So I apologize if this has already been covered. I am having an issue with a calculation in SQL. I want to Counting Distinct Transactions then divide Hours Worked.
“Transactions Per Hour” should only count: Distinct “tbl_TRX”.“TRX #”
This SQL does not work.
COUNT( DISTINCT “tbl_TRX”.“TRX #” ) / ( “tbl_EMP”.“Hours” ) AS “Transactions Per Hour”
Error: Not in aggregate function or group by clause: org.hsqldb.Expression
This SQL works fine when by itself.
COUNT( DISTINCT “tbl_TRX”.“TRX #” ) AS “TRX Count”
SQL Below: Error: Not in aggregate function or group by clause: org.hsqldb.Expression
SELECT DISTINCT "tbl_EMP"."Date", "tbl_EMP"."Personnel"
, COUNT( "tbl_TRX"."TRX #" ) AS "Items Sold"
, COUNT( "tbl_TRX"."TRX #" ) AS "TRX Count"
, "tbl_EMP"."Hours"
, COUNT( "tbl_TRX".* ) / ( "tbl_EMP"."Hours" ) AS "Items Per Hour"
, COUNT( DISTINCT "tbl_TRX"."TRX #" ) / ( "tbl_EMP"."Hours" ) AS "Transactions Per Hour"
, SUM( "tbl_TRX"."Sold Price" ) AS "Total Sold"
FROM { oj "tbl_EMP" LEFT OUTER JOIN "tbl_TRX" ON "tbl_EMP"."Personnel" = "tbl_TRX"."Cashier"
AND "tbl_EMP"."Date" = "tbl_TRX"."Date" }
WHERE ( "tbl_EMP"."Position" = 'Cashier'
AND ( "tbl_EMP"."Date" = :Var_StDtMx OR :Var_StDtMx IS NULL ) )
GROUP BY "tbl_EMP"."Personnel", "tbl_EMP"."Hours", "tbl_EMP"."Date"
ORDER BY "Items Per Hour" DESC
- Side Note
Although the event of an Empolyee having zero transactions is unlikely, their Transactions Per Hour should read zero. Hopefully counting Distinct TRX #'s will solve this problem.
Attached is the Base file in question. I’m using a macro written by Ratslinger to refresh all forms, and set a default date.
TotalRecall.odb (32.7 KB)