エイリアスを使用して、GROUP
        BY、ORDER BY または
        HAVING
        部分のカラムを参照することができます。エイリアスを使用して、カラムにわかりやすい名前を付けることもできます。
      
SELECT SQRT(a*b) as rt FROM table_name GROUP BY rt HAVING rt > 0; SELECT id,COUNT(*) AS cnt FROM table_name GROUP BY id HAVING cnt > 0; SELECT id AS "Customer identity" FROM table_name;
        標準 SQL では、WHERE
        節のエイリアスを参照することはできません。これは、WHERE
        コードが実行される際、カラム値がまだ設定されていない場合があるためです。たとえば、以下のクエリは無効です。
      
SELECT id,COUNT(*) AS cnt FROM table_name WHERE cnt > 0 GROUP BY id;
        WHERE ステートメントを実行して
        GROUP BY
        部分に追加するレコードを決定し、HAVING
        を実行して結果セットからどのレコードを使用するか決定します。
      
This is a translation of the MySQL Reference Manual that can be found at dev.mysql.com. The original Reference Manual is in English, and this translation is not necessarily as up to date as the English version.

