query help
I have a table like this: |ORDERS| |ID| DATE | QNT | LEAD | |342 | 8-12-12 | 32 | F| |345 | 8-15-12 | 12 | S| |349 | 8-16-12 | 9 | R| I am looking for a way to query it with counts by the LEAD column in order to tell what the number of each type lead is, so that I get something like this: F_LEADS S_LEADS R_LEADS 44 122 32 Is this possible? If so can anyone help with syntax? Thanks, Richard -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql
RE: query help
I think this will get you there: SELECT LEAD, COUNT(*) FROM ORDERS GROUP BY LEAD; It'll give you something more like: | LEAD | COUNT(*) | | F | 44 | | S | 122 | | R | 32 | -Original Message- From: Richard Reina [mailto:gatorre...@gmail.com] Sent: Thursday, September 13, 2012 9:51 AM To: mysql@lists.mysql.com Subject: query help I have a table like this: |ORDERS| |ID| DATE | QNT | LEAD | |342 | 8-12-12 | 32 | F| |345 | 8-15-12 | 12 | S| |349 | 8-16-12 | 9 | R| I am looking for a way to query it with counts by the LEAD column in order to tell what the number of each type lead is, so that I get something like this: F_LEADS S_LEADS R_LEADS 44 122 32 Is this possible? If so can anyone help with syntax? Thanks, Richard -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql Notice: This communication may contain privileged and/or confidential information. If you are not the intended recipient, please notify the sender by email, and immediately delete the message and any attachments without copying or disclosing them. LBI may, for any reason, intercept, access, use, and disclose any information that is communicated by or through, or which is stored on, its networks, applications, services, and devices. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql
RE: query help
Transposing is ugly in SQL. It is better done in some other language (PHP, Java, ...) If you must do it in SQL, search for pivot Peter Brawley -Original Message- From: Stillman, Benjamin [mailto:bstill...@limitedbrands.com] Sent: Thursday, September 13, 2012 7:09 AM To: 'Richard Reina'; mysql@lists.mysql.com Subject: RE: query help I think this will get you there: SELECT LEAD, COUNT(*) FROM ORDERS GROUP BY LEAD; It'll give you something more like: | LEAD | COUNT(*) | | F | 44 | | S | 122 | | R | 32 | -Original Message- From: Richard Reina [mailto:gatorre...@gmail.com] Sent: Thursday, September 13, 2012 9:51 AM To: mysql@lists.mysql.com Subject: query help I have a table like this: |ORDERS| |ID| DATE | QNT | LEAD | |342 | 8-12-12 | 32 | F| |345 | 8-15-12 | 12 | S| |349 | 8-16-12 | 9 | R| I am looking for a way to query it with counts by the LEAD column in order to tell what the number of each type lead is, so that I get something like this: F_LEADS S_LEADS R_LEADS 44 122 32 Is this possible? If so can anyone help with syntax? Thanks, Richard -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql Notice: This communication may contain privileged and/or confidential information. If you are not the intended recipient, please notify the sender by email, and immediately delete the message and any attachments without copying or disclosing them. LBI may, for any reason, intercept, access, use, and disclose any information that is communicated by or through, or which is stored on, its networks, applications, services, and devices. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql