Hi,

This is a generic SQL question. I would simplify the question and ask it at
StackOverflow.com

Regards,
Thomas


On Thu, Sep 12, 2013 at 12:38 AM, Anders <[email protected]> wrote:

> Hi,
>
> I need help with creating a query.
>
> Currently it looks like this
>
> SELECT
> COUNT(*) AS ALERTS,
>  EXTRACT (YEAR FROM DATE) AS YEAR,
> EXTRACT (MONTH FROM DATE) AS MONTH,
> EXTRACT (DAY FROM DATE) AS DAY,
>  HOST,
> ALERTLEVEL
> FROM
> ALERTS
> WHERE
> EXTRACT (DAY FROM DATE) > EXTRACT (DAY FROM CURRENT_DATE) -7
>  AND
> EXTRACT (MONTH FROM DATE) >= EXTRACT (MONTH FROM CURRENT_DATE)
> AND
>  HOST = 'HOST'
> GROUP BY
> YEAR,MONTH,DAY,HOST,ALERTLEVEL
> ORDER BY
> YEAR ASC,MONTH ASC,DAY ASC, ALERTLEVEL ASC
>
> --------------
> *Result*:
> *ALERTS  **YEAR  **MONTH  * *DAY  **HOST  **ALERTLEVEL  *5201395HOST164
> 2013 95HOST211201395HOST315201395HOST4162013 98HOST22201399HOST1
>
>
> I would like to have 4 columns for alertlevel instead of one and sum the
> column alerts per day for each alertlevel.
>
> ----------------
> Desired result
>
>
> *YEAR  **MONTH  * *DAY  **HOST  **ALERTLEVEL1  ALERTLEVEL2  ALERTLEVEL3
>  ALERTLEVEL4*
> 201395HOST 5                       64                    11
>       15
> 201398HOST0                       16                     0
>        0
> 201399HOST2                       0                       0
>        0
>
>
> Is this possible to do?
>
> Many thanks for any help!!
>
>
>
>
>
>
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to