WeCodeThings Library
Library of code bits
Glossary    Contact Us
Need a web designer? visit WeCodeThings.Com for more details
Search  
   
Browse by Category


WeCodeThings Library .: SQL .: SQL Sum a Sum MS SQL Server, Oracle, MySQL Sum a Group By



SQL Sum a Sum MS SQL Server, Oracle, MySQL Sum a Group By

SQL SUM A SUM

For some reason, this was hard for me to find when I was searching, so I figured I would post here in hopes that someone
that needs it as bad as I did, comes accross it.

My primary use to a sql statement for a sum a sum is when using a count and group by within a select statement.
For instance:

  1. SELECT COUNT(myvarchar_column) mycount
  2. FROM tblMyTable
  3. GROUP BY myvarchar_column

This returns the count of each unique string in my myvarchar_column.
but what if you want the count to be greater than 5.  Its this simple:

  1. SELECT z.mycount
  2. FROM
  3. (
  4. SELECT COUNT(myvarchar_column) mycount
  5. FROM tblMyTable
  6. GROUP BY myvarchar_column
  7. ) z
  8. WHERE mycount > 5

 



How helpful was this article to you?

Related Articles

article Oracle Trunc First Day of every Month and Last Day of every Month Date
Working in Oracle:  

(No rating)  10-14-2009    Views: 818   
article PHP Simple MySQL Open Configure and Close the Connection to a Database using PHP
Usually you want to create a “config.php”...

(No rating)  5-5-2009    Views: 755   
article How to use cfmail with Godaddy using a try | catch
<cfparam

  4-7-2009    Views: 1227   

User Comments

Add Comment
No comments have been posted.




.: Powered by Lore .:Code by WeCodeThings Website Design and Development