Jump to content

Need an SQL Query - ready to pay!


Recommended Posts

Hi guys,

 

I've just been informed by our accountant that he needs to have a listing of all customers in the state of California and also how much they have paid for the year 2010 so far. This will come into play for us at the end of the year for taxes due to some new law.

 

Anyway, I'm looking to get a query that will output all clients that were active during 2010 that are located in the state of California and how much they spent. Ideally it would be nice to see how much each individual spent, but a lump sum total would be fine too.

 

Anyone up for a challenge? <<removed>>

Link to comment
Share on other sites

SELECT SUM( i.total ) 
FROM tblinvoices i, tblclients c
WHERE i.status = 'Paid'
AND i.datepaid LIKE  '2010-%'
AND (
c.state LIKE 'cali%'
OR c.state = 'CA'
)
AND c.id = i.userid

 

 

EDIT: heres the code if you want to get it per userid:

 

SELECT c.id, SUM( i.total ) AS total
FROM tblinvoices i, tblclients c
WHERE i.status = 'Paid'
AND i.datepaid LIKE '2010-%'
AND (
c.state LIKE 'cali%'
OR c.state = 'CA'
)
AND c.id = i.userid
GROUP BY c.id

Edited by laszlof
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated