mercredi 2 mars 2016

sqlite - sum values based on concat value with some specific

I have two tables

In table "products" there are products and prices as bellow:

Product_id  Price
------------------
Product1   100
Product2   50
Product3   20
Product4   15
Product5   10

I receive another table which is group_concat fixed as bellow:

Customer    Product                                           Price
John        Product1, Product4, Product3, Product5            null
Peter       Product5, Product2                                null

Now I am working to find solution how to calculate only the most n number of most expensive products and sort it in a table. In this demo case n number = 3. If row doesn't reach n=3, then it's fine to calculate only which are below n3.

Customer    Product                                           Price
John        Product1, Product4, Product3                      135
Peter       Product5, Product2                                25

Any hint would be more than usefull. Thank you in advance. sorry for my english

Aucun commentaire:

Enregistrer un commentaire