Tony
Tony

Reputation: 12695

T-SQL How to get SUM() from a subquery

I need fast answer (I can't check that code right now):

is that query works ? I need to get the total sum of a column values from the subquery, something like that:

  select sum(select time from table) as sometimes group by sometimes

Upvotes: 1

Views: 1037

Answers (3)

manman169
manman169

Reputation: 11

select avg(field_val)
from table1
where field_val in (
  SELECT TOP 3 field_val
  FROM table1
  ORDER BY field_val DESC
)

Upvotes: 1

That doesnot work, try this

select sum(time) as sumtime from table

Upvotes: 1

Kendrick
Kendrick

Reputation: 3787

That isn't a subquery. You only have 1 from...

Upvotes: 0

Related Questions