mysql - Summing-up For an Arbitrary List of Rows -
i wish write this:
select sum(weight) items itemid in (4217,4575,6549,4217)
where itemid
primary key, , sqlite , mysql process expected, i.e. add 4217-th row sum twice, don't.
is there @ least in mysql i'm not aware of that's intended cases this? if not, workaround like? row can have number of duplicates in list. list can big although in cases small.
i don't know out of box functionality can this. here workaroud. can insert values temp table , use join:
create temporary table list(id int); insert list(id) values(4217),(4575),(6549),(4217); select sum(i.weight) items join list l on i.itemid = l.id;
Comments
Post a Comment