Simulating window functions in Firebird -
is there can me query.
here table.
when run query. result illustrated below.
total_bins_per_site field sum of bin count group site. here query
select x.site, x.status, x.total_bins_per_bin, (select sum(bin_count) ts_bins_per_site id = x.id) total_bins_per_site (select id, sum(bin_count) total_bins_per_bin, site site, status status ts_bins_per_site status = 'p' , id = ( select a.id ts_rec_data join ts_main_rec b on a.rec_id = b.id b.lot_id = 'qyyzca004k' , b.tester_id = 'ltxmxspc035' , a.datemodified = '5/30/2014 10:01:05') group site, status, id ) x
it working problem total_bins_per_site sum bin count, expected sum bin_count group site. example site 1, total_bins_per_site suppose 5 because bin_count 4 + bin_count 1 in site 1. know query in 5th line missing "group site", when added 5th line, error says "multiple rows in singleton select". can me out of here? much!
the problem subquery in select has condition where id = x.id
, instead should use where site = x.site
(or maybe where site = x.site , id = x.id
) items site in summation.
in upcoming firebird 3 can simplified using window functions, example using
sum(total_bins_per_bin) on (group x.site) total_bins_per_site
instead of subquery in select.
Comments
Post a Comment