sql server - Syntax error with sum in sql code -


i'm having issues sql server code. trying results list first 4 columns of select statement. keep getting syntax errors , unsure why.

what want pull entityid, acctnum, period define but, don't want see period in results want them summed together. ie want see total activity activity column instead of rows each period.

select      entityid, acctnum, acctname, activity     (select            g.entityid 'entityid'          g.acctnum 'acctnum'          sum(g.activity) 'activity'          h.acctname 'acctname'                sqldata.dbo.glsum  g      inner join           sqldata.dbo.gacc h on g.acctnum = h.acctnum                  g.entityid = '85000'          g.period < '201703'          g.acctnum = '569300000') 

you need group clause https://docs.microsoft.com/en-us/sql/t-sql/queries/select-group-by-transact-sql, commas in select list, , keywords between elements, , outer select seems bit redundant.

select       g.entityid 'entityid',     g.acctnum 'acctnum',     sum(g.activity) 'activity',     h.acctname 'acctname'      sqldata.dbo.glsum  g inner join      sqldata.dbo.gacc h on g.acctnum = h.acctnum        g.entityid = '85000'     , g.period < '201703'     , g.acctnum = '569300000'  group       g.entityid,     g.acctnum,     h.acctname 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -