SQL help
Posted in 1998
Topics: SQL Development & Query Writing
I am a v5.1 trying to run a query that will contain a subquery utilizing the sum(field) function. It goes a little something like this... select cust_name, (select sum(sold_amt) from invoices where MONTH(inv_date)=1 and YEAR(inv_date)=1998), (select sum(profit_amt) from invoices where MONTH(inv_date)=1 and YEAR(inv_date)=1998)) from invoices group by 1 This query runs perfectly if a where clause limiting the selection to 1 customer is added to each subquery and to the end of the whole query. If I run it for the entire customer base however, I get the total sum of sold amount and profit amount for all customers returned with each customer name. The result I am looking for is....... {|customer name | (customer)MTD sold_amt | (customer)MTD profit_amt | } .....for each individual customer. I am getting.... {customer name | (total ALL customers)MTD sold_amt | (total ALL customers)MTD profit_amt}... Any suggestions would be greatly appreciated