I ran across the following in a stored procedure:
for
select 1
from scan_queue
where ( date_time_locked is null )
and ( scan_seqno >= :varMinScanSeqno )
and ( scan_seqno <= :varMaxScanSeqno )
group by loan_id, collateral_id, insurance_id
into varNotUsed
do
varItemsToScan = varItemsToScan + 1;
My first thought was that this is probably an inefficient way of counting the number of groups, but my second thought was, "hey, how would you write that in a single query, anyway?" And I didn't have a good answer. (So this is more of an academic question.) I am not looking for a solution that concatenates the IDs, like so:
select count(distinct loan_id || collateral_id || insurance_id)
from scan_queue
where ( date_time_locked is null )
and ( scan_seqno >= :varMinScanSeqno )
and ( scan_seqno <= :varMaxScanSeqno )
What is the best way to query this information?
EDIT: Since I apparently did not make this clear enough, I am using Firebird v1.5.