Dc Redwing
Dc Redwing

Reputation: 1791

Oracle SQL suming value without using aggregate function

I am studying for my SQL class and I'm stuck on a about writing a SQL query without using aggregate functions.

For example, we have table item.

item_id | price
1       | 10
2       | 20
3       | 40

I can sum up the prices for the various items using the SUM function to get a value of 70

SELECT SUM(price)
  FROM item

How can I get the total price without using any aggregate functions?

Upvotes: 0

Views: 1112

Answers (1)

Justin Cave
Justin Cave

Reputation: 231671

If you can use analytic functions, you can always do

SELECT DISTINCT SUM(price) OVER ()
  FROM item

This isn't a sensible reason to use analytic functions since you really do want to use an aggregate function. But it is valid.

Upvotes: 1

Related Questions