SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with SQL query please

    I have this query:

    Code:
    	$sql = "
    		SELECT job.project_manager,
    		SUM(job.ssoc_ytd) AS total_ssoc_ytd,
    		SUM(job.billed) AS total_billed,
    		SUM(job.appr_adj) AS total_appr_adj,
    		SUM(job.unappr_adj) AS total_unappr_adj,
    		SUM(unbilled_item.amount) AS total_unbilled,
    		SUM(invoice.amount) AS total_unpaid,
    		user.first_name,
    		user.surname
    		FROM job
    		LEFT JOIN user ON (user.employee_number=job.project_manager)
    		LEFT JOIN unbilled_item ON (job.job_number=unbilled_item.job_number)
    		LEFT JOIN invoice ON (job.job_number=invoice.job_number)
    		WHERE user.work_group = $group
    		GROUP BY user.employee_number
    		ORDER BY user.surname
    		" ;
    Now the only SUM that appears to verify is the unbilled_amout one. I've not done any development for a couple of months and my head's about to explode.

    Any help in pointing out my brainfade would be greatly appreciated.

    Thanks

    Matt.

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In future please don't duplicate. It causes WAY too much confusion, as this has proved.
    Last edited by weirdbeardmt; Apr 23, 2002 at 04:17.
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm assuming that as you're using LEFT JOIN's, there are chances of Null values/records being returned. Have you tried SUM( IsNull( Field_Name, 0 ) ) for each of your SUM values? Just an untested thought....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •