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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -