Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Apply Filtering Criteria at Group Level
How To Apply Filtering Criteria at Group Level? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY
✍: FYIcenter.com
If you want to return only specific groups from the query, you can apply filtering criteria at the group level by using the HAVING clause inside the GROUP BY clause. Note group functions can also be used in HAVING conditions. The following tutorial exercise gives you some good HAVING example:
mysql> SELECT tag, COUNT(*), MIN(created), AVG(counts) FROM fyi_links GROUP BY tag HAVING AVG(counts) > 3.8; +------+----------+---------------------+-------------+ | tag | COUNT(*) | MIN(created) | AVG(counts) | +------+----------+---------------------+-------------+ | DEV | 2 | 2004-01-01 00:00:00 | 4.0000 | | SQA | 2 | 2003-01-01 00:00:00 | 7.0000 | +------+----------+---------------------+-------------+ 2 rows in set (0.00 sec) mysql> SELECT tag, COUNT(*), MIN(created), AVG(counts) FROM fyi_links GROUP BY tag HAVING COUNT(*) > 2; +------+----------+---------------------+-------------+ | tag | COUNT(*) | MIN(created) | AVG(counts) | +------+----------+---------------------+-------------+ | DBA | 3 | 2005-01-01 00:00:00 | 3.6667 | +------+----------+---------------------+-------------+ 1 row in set (0.00 sec)
2007-05-11, 6208👍, 0💬
Popular Posts:
Why is it preferred to not use finalize for clean up? Problem with finalize is that garbage collecti...
Who Developed HTML? HTML was originally developed by Tim Berners-Lee while at CERN, and popularized ...
How do I force the Dispose method to be called automatically, as clients can forget to call Dispose ...
Jack developed a program by using a Map container to hold key/value pairs. He wanted to make a chang...
How To Create an Add-to-My-Yahoo Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...