Classifying counts of repeat visits per user for a website
MySQL version 8 supports common table expression.  If you want to differentiate between the three sub queries, use a column containing literal:

WITH SESSIONS_THIS_MONTH AS (
SELECT ipaddress,
        COUNT(*) AS sess
   FROM analytics
   WHERE trunc(datecreated) &gt; getdate() - interval '30 days'
   GROUP BY trunc(datecreated), ipaddress
)
SELECT 'MORE THAN 100' AS CATEGORY, 
       COUNT(SESSIONS_THIS_MONTH.sess) as acount, 
       SUM(SESSIONS_THIS_MONTH.sess) as asum, 
       AVG(SESSIONS_THIS_MONTH.sess) as aavg
FROM SESSIONS_THIS_MONTH
WHERE sess &gt;= 100

UNION ALL

SELECT 'BETWEEN 50 AND 100' AS CATEGORY, 
       COUNT(SESSIONS_THIS_MONTH.sess) as bcount, 
       SUM(SESSIONS_THIS_MONTH.sess) as bsum, 
       AVG(SESSIONS_THIS_MONTH.sess) as bavg
FROM SESSIONS_THIS_MONTH
WHERE sess &lt; 100 AND sess &gt;=50

UNION ALL

SELECT 'LESS THAN 50' AS CATEGORY, 
       COUNT(SESSIONS_THIS_MONTH.sess) as ccount, 
       SUM(SESSIONS_THIS_MONTH.sess) as csum, 
       AVG(SESSIONS_THIS_MONTH.sess) as cavg
FROM SESSIONS_THIS_MONTH
WHERE sess &lt; 50