vivek modi
vivek modi

Reputation: 497

correct subquery in sum function syntax error

I have a subquery like

Select id, 
       sum(select fran_payment.amount 
           from fran_payment 
           where fran_payment.fran_id = id) as paid,
       sum(select purchase.commission_amount 
           from purchase 
           where purchase.fran_id = id) as commission
from franchiese;

It's giving me syntax error near select fran_payment

Upvotes: 0

Views: 83

Answers (1)

forpas
forpas

Reputation: 164089

You can't sum over a query.
You must specify a column to sum over inside a query and this sum will be returned:

Select f.id, 
       (
         select sum(fran_payment.amount) 
         from fran_payment 
         where fran_payment.fran_id = f.id
       ) as paid,
       (
         select sum(purchase.commission_amount) 
         from purchase 
         where purchase.fran_id = f.id
       ) as commission
from franchiese as f;

Upvotes: 2

Related Questions