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

1 次查看(过去 30 天)
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 个评论
Geoff Hayes
Geoff Hayes 2017-2-9
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?

请先登录,再进行评论。

回答(1 个)

Sindhu Priya
Sindhu Priya 2017-2-14
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

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by