473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Cant get sql statement to work in mysql 5

Hello,

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

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT id, name, jv_signups, mem_signups, (
  2. SELECT SUM( jv_signups ) 
  3. ) + ( 
  4. SELECT SUM( mem_signups ) ) AS total
  5. FROM members
  6. WHERE clicktracking >0
  7. AND LEVEL =2
  8. ORDER BY total DESC 
  9. LIMIT 0 , 10";

but on mysql v5 i get the following error:
Expand|Select|Wrap|Line Numbers
  1. 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 
  2.  

if i add the group by null like this:

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT id, name, jv_signups, mem_signups, (
  2. SELECT SUM( jv_signups ) 
  3. ) + ( 
  4. SELECT SUM( mem_signups ) ) AS total
  5. FROM members
  6. WHERE clicktracking >0
  7. AND LEVEL =2
  8. ORDER BY total DESC
  9. GROUP BY NULL 
  10. LIMIT 0 , 10";
it only shows one result instead of 10
any help would be greatly appriciated

Scott
Mar 28 '08 #1
5 1687
Markus
6,050 Expert 4TB
This would be more suited to the mysql forum.

try there :)
Mar 28 '08 #2
ronverdonk
4,258 Expert 4TB
This is a MySQL problem/question, so you are in the wrong forum!
I will move this thread.

moderator
Mar 28 '08 #3
ronverdonk
4,258 Expert 4TB
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
Mar 28 '08 #4
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+regularreferals


scott
Mar 28 '08 #5
ronverdonk
4,258 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. select name, jvreferals+regularreferals as total from members order by total desc limit 10;
2. assuming you have > 1 member per table and you want to GROUP total their 2 columns by name, and sort on total desc.
Expand|Select|Wrap|Line Numbers
  1.  select name, sum(jvreferals)+sum(regularreferals) as total from members group by name order by total desc limit 10;
Ronald
Mar 29 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tiernan | last post by:
Hey everybody. I'm verry new to PHP and MYSQL and have been working on a form that when it is submitted stores the information into a mysql database. The main problem is that i'm trying to finish...
1
by: berehneh | last post by:
i have set up a site in my local host in my pc but when i upload it to site i recieve this error: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in...
3
by: Aaron Brockhurst | last post by:
Hi Can anyone help? I cant get my php script to insert or delete records into a mysql table. I can view them all fine but that's about it. I've checked the user permissions on mysql and...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
4
by: gregsands | last post by:
Hi I have read all (ok most) of the posts relating to "Call to undefined function mysql_connect()", read the manual on PHP.net and done eveything thats ive been asked to do but cant get PHP to...
6
by: ancelotp | last post by:
hi, i'm new to sql i'd appretiate if someone would helpme out with this doudt i have CODE: CREATE TABLE entry ( uno int(6) NOT NULL auto_increment, fname varchar(30) NOT NULL, sname...
1
by: ScottCase | last post by:
Hello, I have this sql statement and it works fine with mysql v4 $query = "SELECT id, name, jv_signups, mem_signups, ( SELECT SUM( jv_signups ) ) + ( SELECT SUM( mem_signups ) ) AS total...
6
flexsingh
by: flexsingh | last post by:
Hello there, I have constructed a option of choosing a court only available when member no = "0". This works fine and is in the first code: - <html> <head> </head> <body background="main...
1
by: Maklar60 | last post by:
I am attempting to execute an INSERT statement on my page but continually get the following error: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Incorrect syntax near '<'. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.