SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's wrong with this derived table query?

    The derived table accounts for the fact that there are multiple records for each tracking_number. It is summing all the net_amount columns for each tracking_number. Then the rest of the query is trying to generate data to drive a histogram with bins that are 3 digits apart.

    Code:
    SELECT 
       COUNT( s.tracking_number ) AS freq
       , SUM( s.net_amount ) - ( SUM( s.net_amount ) mod3 ) AS label
    FROM (
       SELECT b.tracking_number, SUM( b.net_amount ) AS net_amount
       FROM gvdb_gs_ups_billing AS b
       GROUP BY b.tracking_number
    ) AS s
    GROUP BY 
       SUM( s.net_amount ) - ( SUM( s.net_amount ) mod3 )
    ORDER BY 
       SUM( s.net_amount ) - ( SUM( s.net_amount ) mod3 ) ASC
    This is the error I am getting:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod3 ) AS label FROM ( SELECT b.tracking_number , SUM( b.net_amount ) as net_a'

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •