Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Merging tuples together

When I query my Mysql table to get results. I get a tuple back.

The tuple is like this:

(('Book 1', 1), ('Book 2', 1), ('Book 1', 2))

How do I get my tuple to be like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(('Book 1', 3), ('Book 2', 1))

Any suggestions in python or SQL would be helpful.

>Solution :

you can try SQL group by statement with aggregate function ‘sum’
example

select book_name,sum(book_quantity) 
from your_table_name 
group by book_name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading