Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Subject: Need help to create a query

Subject: Need help to create a query

2007-11-05       - By N?stor

 Back
I have a table with about 9 fields, and record ID field an
agency name field and the # of gallons that a erson pledges to save:
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
|ID| agency| 5g | 8g | 10g | 12g | 15g | 18g | 20g |
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---

Each of the gallon fields are either a 0 or  the # of gallons for that
column:
|1 | Helix | 0 | 8 | 10 |  0  | 15 |  0  |  0 |
|2 | corp  | 5 | 8 |   0 | 12 | 15 | 18 | 20 |
|3 | Helix | 5 | 8 | 10 |  0  | 15 |  0  | 20 |
|4 | Helix | 5 | 8 | 10 |  0  | 15 |  0  |  0 |
|5 | corp  | 5 | 0 |   0 | 12 | 15 |   0 | 20 |

I need to be able to obtain the top 5 pledges per agency:
| Helix |8g = 3|10g =3 |15g = 3 |5g = 2 |20g = 2 |
| Corp |5g = 2 | 12g = 2 |15g = 2 | 20g = 2| 8g = 1|

Thanks,

Nestor :-)