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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -