Forum Discussion
SreekanthG
Nov 03, 2024Copper Contributor
Group items based on criteria
Hi, I have different items which needs to be packed in different bags based on the following criteria. I have an itemized spreadsheet with the weight of each item (attached in link). I am looking fo...
peiyezhu
Nov 03, 2024Bronze Contributor
create temp table aa2 as
select rowid old_rowid,row_number() over ( partition by Category) grp,* from Sheet1;
create temp table aa3 as
select * from aa2 order by grp;
create temp table aa as
select *,sum(weight) over (order by rowid) acc from aa3 ;
//select * from aa limit 20;
create temp table bb as
select acc from aa union select rowid*2500 acc from aa;
create temp table cc as
select * from bb left join aa using(acc);
select *,'400'||iif(acc%2500=0,0,1)+acc/2500 bags from cc where old_rowid is not null;