Average distinct value : Distinct « Select Clause « SQL / MySQL






Average distinct value

       
mysql>
mysql>
mysql>
mysql> CREATE   TABLE PENALTIES
    ->         (PAYMENTNO      INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          PAYMENT_DATE   DATE         NOT NULL,
    ->          AMOUNT         DECIMAL(7,2) NOT NULL,
    ->          PRIMARY KEY    (PAYMENTNO)          );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO PENALTIES VALUES (1,  6, '1980-12-08',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (2, 44, '1981-05-05', 75);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (3, 27, '1983-09-10',100);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (4,104, '1984-12-08', 50);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (5, 44, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (6,  8, '1980-12-08', 25);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (7, 44, '1982-12-30', 30);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO PENALTIES VALUES (8, 27, '1984-11-12', 75);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> SELECT   AVG(DISTINCT AMOUNT)
    -> FROM     PENALTIES;
+----------------------+
| AVG(DISTINCT AMOUNT) |
+----------------------+
|            56.000000 |
+----------------------+
1 row in set (0.00 sec)

mysql>
mysql> drop table penalties;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
    
  








Related examples in the same category

1.Use DISTINCT to get non-dupliate records
2.Use DISTICNT to get unique value
3.Eliminating Duplicate Data Using DISTINCT 1
4.Eliminating Duplicate Data Using DISTINCT 2
5.Select distinct records using JOIN
6.The SQL key word DISTINCT has the effect that equivalent data records are output only once.
7.DISTINCT works with multiple-column output too.
8.how many different drivers there are, use COUNT(DISTINCT)
9.DISTINCT with two columns
10.DISTINCT works with expressions, not just column values.
11.Inserting name values into the multisequence table generates separate sequences for each distinct name:
12.Count distinct
13.Distinct sub string
14.Return a list of surnames, with each surname appearing only once?
15.The fraction of the records that contain unique or non-unique names: