How to get the sum of of particular column using group by functionality while pulling data from sql using jdbc?

1 visualizzazione (ultimi 30 giorni)
I am retrieving data from the database using a select query. I am able to get the data using curs.Data. However, now I want to find the sum of a particular column using group by clause on two columns.
Example: A=[1, 2.5, 3;1, 2.5, 4;1, 1.5, 3;2, 2.5, 3;2, 3.5, 4 ] then I want the output like B=[1, 2.5, 7; 1,1.5,3;2, 2.5, 3;2, 3.5, 4 ]
  1 Commento
Geoff Hayes
Geoff Hayes il 9 Feb 2017
Aishwarya - so if two rows have identical elements in the first two columns, then you want to combine the two rows and just sum the third column? So the first two rows of A are
1.0000 2.5000 3.0000
1.0000 2.5000 4.0000
and this becomes
1.0000 2.5000 7.0000
Is that correct?

Accedi per commentare.

Risposte (1)

Sindhu Priya
Sindhu Priya il 14 Feb 2017
You can try this SQL query to group the data
select column1,column2,sum(column3) as column3 from tablename group by column1,column2;
Regards,
Sindhu

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by