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

1 view (last 30 days)
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 Comment
Geoff Hayes
Geoff Hayes on 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?

Sign in to comment.

Answers (1)

Sindhu Priya
Sindhu Priya on 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!