Cant get sql statement to work in mysql 5

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ScottCase
    New Member
    • Mar 2008
    • 3

    Cant get sql statement to work in mysql 5

    Hello,

    I have this sql statement and it works fine with mysql v4

    [CODE=mysql]$query = "SELECT id, name, jv_signups, mem_signups, (
    SELECT SUM( jv_signups )
    ) + (
    SELECT SUM( mem_signups ) ) AS total
    FROM members
    WHERE clicktracking >0
    AND LEVEL =2
    ORDER BY total DESC
    LIMIT 0 , 10";[/CODE]


    but on mysql v5 i get the following error:
    Code:
    DATABASE ERROR: ERRNO: 1140 ERROR: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause MSG:Invalid SQL: SELECT id, name, jv_signups, mem_signups, ( SELECT SUM( jv_signups ) ) + ( SELECT SUM( mem_signups ) ) AS total FROM members WHERE clicktracking >0 AND LEVEL =2 LIMIT 0 , 10

    if i add the group by null like this:

    [CODE=mysql]$query = "SELECT id, name, jv_signups, mem_signups, (
    SELECT SUM( jv_signups )
    ) + (
    SELECT SUM( mem_signups ) ) AS total
    FROM members
    WHERE clicktracking >0
    AND LEVEL =2
    ORDER BY total DESC
    GROUP BY NULL
    LIMIT 0 , 10";[/CODE]
    it only shows one result instead of 10
    any help would be greatly appriciated

    Scott
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    This would be more suited to the mysql forum.

    try there :)

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      This is a MySQL problem/question, so you are in the wrong forum!
      I will move this thread.

      moderator

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        The way you SUM is bound to lead to 1 result only.
        Please explain in wordt what you want to accomplish and show some table describe, that way it will be much clearer what you want to achieve.

        ROnald

        Comment

        • ScottCase
          New Member
          • Mar 2008
          • 3

          #5
          Hello

          What i am doing is getting the top 10 referrers.

          the html table has the following fields

          name jvreferals regularreferals totalreferals


          i need the sql to add the jvreferals and regular referals together and then display the top 10 sorted by the total of jvreferals+regu larreferals


          scott

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            I must confess that I still do not understand comparing your explanation to your SQL code.

            Let me give it a try:

            1. assuming you have only 1 member per table and you want to total their 2 columns per name, soted on total desc, then what is wrong with the following statement[code=mysql]select name, jvreferals+regu larreferals as total from members order by total desc limit 10;[/code]
            2. assuming you have > 1 member per table and you want to GROUP total their 2 columns by name, and sort on total desc.[code=mysql] select name, sum(jvreferals) +sum(regularref erals) as total from members group by name order by total desc limit 10;[/code]Ronald

            Comment

            Working...