Re: Help for a student please

From: Mike Dwyer <dwyermj_at_co.larimer.co.us>
Date: Mon, 20 Mar 2000 08:51:49 -0700
Message-ID: <mSrB4.49$nG2.40385_at_wdc-read-01.qwest.net>


, count( decode (to_char( hiredate, 'YYYY'), '1980',1, 0)) '1980' , count( decode (to_char( hiredate, 'YYYY'), '1981',1, 0)) '1981'

decode is Oracle's CASE function.
The first argument is the test value: to_char( hiredate, 'yyyy'). The second two arguments are the first case: = '1980', and the result: 1. The last argument is the default result: 0.

Arguments 2 and 3 may be repeated with different values and results, but in your problem, you want each "case" in a separate column.

Karen Standish <standish_at_kc.rr.com> wrote in message news:fWbB4.438$4V.42707_at_typhoon2.kc.rr.com...
> Good Evening and HELP PLEASE,
> I am stumped on one of my class questions. Currently taking a class for
SQL
> in oracle. The question is:
>
> create a query that will display the total number of employees and of that
> total the number who were hired in 1980, 1981, 1982, and 1983, label the
> columns appropriately.
>
> The query should look like this.
>
> Total 1980 1981 1982 1983
> _____ ____ ____ ____ ____
> 14 1 10 2 1
>
> I know this is not correct but I am just absolutely blocked.
>
> SELECT COUNT(*) AS TOTAL
> ,if
> ,count(TO_CHAR(HIREDATE,'YYYY')) "1980"
> ,count(TO_CHAR(HIREDATE,'YYYY')) "1981"
> ,count(TO_CHAR(HIREDATE,'YYYY')) "1982"
> ,count(TO_CHAR(HIREDATE,'YYYY')) "1987"
> FROM emp
> group by to_char(hiredate,'yyyy')
> /
>
>
> --
> Karen Standish
> standish_at_kc.rr.com
>
>
>
>
Received on Mon Mar 20 2000 - 16:51:49 CET

Original text of this message