Database Reference
In-Depth Information
following statements show the different sender/recipient pairs in the mail table and the
number of such pairs:
mysql> SELECT DISTINCT srcuser, dstuser FROM mail
-> ORDER BY srcuser, dstuser;
+---------+---------+
| srcuser | dstuser |
+---------+---------+
| barb | barb |
| barb | tricia |
| gene | barb |
| gene | gene |
| gene | tricia |
| phil | barb |
| phil | phil |
| phil | tricia |
| tricia | gene |
| tricia | phil |
+---------+---------+
mysql> SELECT COUNT(DISTINCT srcuser, dstuser) FROM mail;
+----------------------------------+
| COUNT(DISTINCT srcuser, dstuser) |
+----------------------------------+
| 10 |
+----------------------------------+
See Also
Recipe 8.2 shows how to use a view to “encapsulate” the summary expressions.
Recipe 8.6 further discusses the difference between COUNT(*) and COUNT( expr ) . The
SUM() and AVG() functions are especially useful in statistical applications. They're ex‐
plored further in Chapter 15 , along with STD() , a related function that calculates stan‐
dard deviations.
8.2. Creating a View to Simplify Using a Summary
Problem
You want to make it easier to perform a summary.
Solution
Create a view that does it for you.
Discussion
If you often need a given summary, a technique that enables you to avoid typing the
summarizing expressions repeatedly is to use a view (see Recipe 3.7 ). For example, the
Search WWH ::




Custom Search