sql - How to do sum of column in mssql -


i have written following query name , amount :

  select fm.familyname,qt.amount   registrations rs left join family fm on fm.id = rs.family_id   left join quote qt on qt.id = rs.quote_id   group  fm.familyname,qt.amount 

so above query getting below answer:

name    amount abc     1200 abc     1300 abc     1400 

but want output like:

name    amount  abc    3900 

how can this? have used sum(isnull(cast(qt.amount float),0)) total doing total of individual column.

how can total ?

simply group fm.familyname alone:

select fm.familyname, sum(qt.amount) registrations rs   left join family fm on fm.id = rs.family_id   left join quote qt on qt.id = rs.quote_id group  fm.familyname  

if "operand data type varchar(max) invalid sum operator.", need cast column, like:

select fm.familyname, sum(cast(qt.amount float)) ... 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -