Using MODEL clause and COUNT for not numeric data columns....

Hi ,
Is it possible somehow to use the COUNT function to transform a non-numeric data column to a numeric data value (a counter) and be used in a MODEL clause....????
For example , i tried the following in the emp table of SCOTT dataschema with no desired result...
SQL> select deptno , empno , hiredate from emp;
DEPTNO EMPNO HIREDATE
    20  7369 18/12/1980
    30  7499 20/02/1981
    30  7521 22/02/1981
    20  7566 02/04/1981
    30  7654 28/09/1981
    30  7698 01/05/1981
    10  7782 09/06/1981
    20  7788 18/04/1987
    10  7839 17/11/1981
    30  7844 08/09/1981
    20  7876 21/05/1987
    30  7900 03/12/1981
    20  7902 03/12/1981
    10  7934 23/01/1982
14 rows selected Now , i want to use the MODEL clause in order to 'predict' the number of employees who were going to be hired in the 1990 per deptno...
So , i have constructed the following query which , as expected, does not return the desired results....
SQL>   select deptno , month , year , count_
  2    from
  3    (
  4    select deptno , to_number(to_char(hiredate,'mm')) month ,
  5                to_number(to_char(hiredate , 'rrrr')) year , count(ename) count_
  6    from emp
  7    group by  deptno , to_number(to_char(hiredate,'mm'))  ,
  8                to_number(to_char(hiredate , 'rrrr'))
  9    )
10    model
11    partition by(deptno)
12    dimension by (month , year)
13    measures (count_ )
14    (
15     count_[1,1990]=count_[1,1982]+count_[11,1982]
16    )
17  /
    DEPTNO      MONTH       YEAR     COUNT_
        30          5       1981          1
        30         12       1981          1
        30          2       1981          2
        30          9       1981          2
        30          1       1990
        20          4       1987          1
        20          5       1987          1
        20          4       1981          1
        20         12       1981          1
        20         12       1980          1
        20          1       1990
        10          6       1981          1
        10         11       1981          1
        10          1       1982          1
        10          1       1990 As you see , the measures for the 1990 year is null...because the measure(the count(deptno)) is computed via the group by and not by the MODEL clause...
How should i transform the above query... so as the "count_[1,1982]+count_[11,1982]" will return non-null results per deptno...????
Thanks , a lot
Simon

Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> SELECT department_id, MONTH, YEAR, count_
  2    FROM (SELECT e.department_id
  3                ,to_number(to_char(e.hire_date, 'mm')) MONTH
  4                ,to_number(to_char(e.hire_date, 'rrrr')) YEAR
  5                ,COUNT(e.first_name) count_
  6            FROM employees e
  7            WHERE e.department_id = 20
  8           GROUP BY e.department_id
  9                   ,to_number(to_char(e.hire_date, 'mm'))
10                   ,to_number(to_char(e.hire_date, 'rrrr')));
DEPARTMENT_ID      MONTH       YEAR     COUNT_
           20          8       1997          1
           20          2       1996          1
SQL> --
SQL> SELECT department_id, MONTH, YEAR, count_
  2    FROM (SELECT e.department_id
  3                ,to_number(to_char(e.hire_date, 'mm')) MONTH
  4                ,to_number(to_char(e.hire_date, 'rrrr')) YEAR
  5                ,COUNT(e.first_name) count_
  6            FROM employees e
  7            WHERE e.department_id = 20
  8           GROUP BY e.department_id
  9                   ,to_number(to_char(e.hire_date, 'mm'))
10                   ,to_number(to_char(e.hire_date, 'rrrr')))
11  model
12  PARTITION BY(department_id)
13  dimension BY(MONTH, YEAR)
14  measures(count_)(
15    count_ [1, 1990] = count_ [2, 1996] + count_ [8, 1997]
16  );
DEPARTMENT_ID      MONTH       YEAR     COUNT_
           20          8       1997          1
           20          2       1996          1
           20          1       1990          2
SQL> ---
SQL> SELECT department_id, MONTH, YEAR, count_
  2    FROM (SELECT e.department_id
  3                ,to_number(to_char(e.hire_date, 'mm')) MONTH
  4                ,to_number(to_char(e.hire_date, 'rrrr')) YEAR
  5                ,COUNT(e.first_name) count_
  6            FROM employees e
  7           GROUP BY e.department_id
  8                   ,to_number(to_char(e.hire_date, 'mm'))
  9                   ,to_number(to_char(e.hire_date, 'rrrr')))
10  model ignore nav
11  PARTITION BY(department_id)
12  dimension BY(MONTH, YEAR)
13  measures(count_)(
14    count_ [1, 1990] = count_ [2, 1996] + count_ [8, 1997]
15  );
DEPARTMENT_ID      MONTH       YEAR     COUNT_
          100          8       1994          2
           30         12       1997          1
          100          3       1998          1
           30          7       1997          1
                       5       1999          1
           30         12       1994          1
           30         11       1998          1
           30          5       1995          1
          100          9       1997          2
          100         12       1999          1
           30          8       1999          1
                       1       1990          0
           30          1       1990          0
          100          1       1990          0
           90          9       1989          1
           20          8       1997          1
           70          6       1994          1
93 rows selected
SQL>

Similar Messages

  • Should I use both GetList and  GetDetail for creating a Data Object?

    Hello, all.
    At first, Thanks for your interesting.
    1. I wounder that  I can make a BAPI Wrapper as Data Object using only GetList.
    When I make a BAPI Wrapper as Data Object using only GetList, SAP shows me a message.
    The message says Data Object can have one root node only (hierarchy = 1 ).
    It means I should use both GetList and  GetDetail.
    I understand that.
    If i need to use only GetList, is there any way?
    Thanks for your interesting again.

    Hi
    I think you are trying to import BAPI wrapper as data object and you are using only "Getlist" BAPI.
    In such case, the data object created will have only root node. i.e Hierarchy =1.
    This is becuse the GetList BAPI has only the info about root node.(i.e, table parameter).
    If you have multiple tables in BE and you want to create a DO with multiple node(hierarchy >1) using BAPI wrapper import, then you have to use "GetDetail" BAPI along with GetList.
    Regards
    Rohith

  • Avoiding null and duplicate values using model clause

    Hi,
    I am trying to use model clause to get comma seperated list of data : following is the scenario:
    testuser>select * from test1;
    ID VALUE
    1 Value1
    2 Value2
    3 Value3
    4 Value4
    5 Value4
    6
    7 value5
    8
    8 rows selected.
    the query I have is:
    testuser>with src as (
    2 select distinct id,value
    3 from test1
    4 ),
    5 t as (
    6 select distinct substr(value,2) value
    7 from src
    8 model
    9 ignore nav
    10 dimension by (id)
    11 measures (cast(value as varchar2(100)) value)
    12 rules
    13 (
    14 value[any] order by id =
    15 value[cv()-1] || ',' || value[cv()]
    16 )
    17 )
    18 select max(value) oneline
    19 from t;
    ONELINE
    Value1,Value2,Value3,Value4,Value4,,value5,
    what I find is that this query has duplicate value and null (',,') coming in as data has null and duplicate value. Is there a way i can avoid the null and the duplicate values in the query output?
    thanks,
    Edited by: orausern on Feb 19, 2010 5:05 AM

    Hi,
    Try this code.
    with
    t as ( select substr(value,2)value,ind
            from test1
            model
            ignore nav
            dimension by (id)
            measures (cast(value as varchar2(100)) value, 0 ind)
            rules
            ( ind[any]=  instr(value[cv()-1],value[cv()]),
            value[any] order by id = value[cv()-1] || CASE WHEN value[cv()] IS NOT NULL
                                               and ind[cv()]=0     THEN ',' || value[cv()] END      
    select max(value) oneline
    from t;
    SQL> select * from test1;
            ID VALUE
             1 Value1
             2 Value2
             3 Value3
             4 Value4
             5 Value4
             6
             7 value5
             8
    8 ligne(s) sélectionnée(s).
    SQL> with
      2   t as ( select substr(value,2)value,ind
      3          from test1
      4          model
      5          ignore nav
      6          dimension by (id)
      7          measures (cast(value as varchar2(100)) value, 0 ind)
      8          rules
      9          ( ind[any]=  instr(value[cv()-1],value[cv()]),
    10          value[any] order by id = value[cv()-1] || CASE WHEN value[cv()] IS NOT NULL
    11                                             and ind[cv()]=0     THEN ',' || value[cv()] END 
    12          )
    13        )
    14   select max(value) oneline
    15   from t;
    ONELINE
    Value1,Value2,Value3,Value4,value5
    SQL>

  • Hello, I'm using Mountain Lion and mail does not leave the mails on the server, either on iCloud nor on other suppliers (orange). They are both using iMap protocol... Any place where I could change this ? Thanks for any hall; Christian

    Hello, I'm using Mountain Lion and mail does not leave the mails on the server, either on iCloud nor on other suppliers (orange). They are both using iMap protocol... Any place where I could change this ? Thanks for any hall; Christian

    Under what circumstances does mail "not leave the mails on the server"?
    If you mean that you delete them (or move them out of the inbox) on one device and then find them not in the inbox on the server when you look from another device, that's how IMAP is supposed to work. (Note that the deletion or moving might be the result of rules you have set up in Mail.)
    If you mean something else, please explain your issue in more detail.

  • I tried to use the iPhone hot spot feature for the first time to use my kindle outside. I followed the directions n I saw the network came up I used my password and I could not connect. What am I'm doing wrong. Please help

    I tried to use the iPhone hot spot feature for the first time to use my kindle outside. I followed the directions n I saw the network came up I used my password and I could not connect. What am I'm doing wrong. Please help

    I tried to use the iPhone hot spot feature for the first time to use my kindle outside. I followed the directions n I saw the network came up I used my password and I could not connect. What am I'm doing wrong. Please help

  • Unable to display data no entry in the table without using Model clause

    Hi,
    I've an urgent requirement described below :
    The previously posted Question has been answerted using Model Clause:
    Is there any way out to solve it without using Model clause:
    I've a table named as "sale" consisting of three columns : empno, sale_amt and sale_date.
    (Please ref. The table script with data as given below)
    Now if I execute the query :
    "select trunc(sale_date) sale_date, sum(sale_amt) total_sale from sale group by trunc(sale_date) order by 1"
    then it displays the data for the dates of which there is an entry in that table. But it does not display data for the
    date of which there is no entry in that table.
    If you run the Table script with data in your schema, then u'll see that there is no entry for 28th. Nov. 2009 in
    sale table. Now the above query displays data for rest of the dates as its are in sale table except for 28th. Nov. 2009.
    But I need its presence in the query output with a value of "sale_date" as "28th. Nov. 2009" and that of "total_sale" as
    "0".
    Is there any means to get the result as I require?
    Please help ASAP.
    Thanks in advance.
    Create table script with data:
    CREATE TABLE SALE
    EMPNO NUMBER,
    SALE_AMT NUMBER,
    SALE_DATE DATE
    SET DEFINE OFF;
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (100, 1000, TO_DATE('12/01/2009 10:20:10', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (100, 1000, TO_DATE('11/30/2009 10:21:04', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (100, 1000, TO_DATE('11/29/2009 10:21:05', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (100, 1000, TO_DATE('11/26/2009 10:21:06', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (100, 1000, TO_DATE('11/25/2009 10:21:07', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (200, 5000, TO_DATE('11/27/2009 10:23:06', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (200, 4000, TO_DATE('11/29/2009 10:23:08', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (200, 3000, TO_DATE('11/24/2009 10:23:09', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (200, 2000, TO_DATE('11/30/2009 10:23:10', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (300, 7000, TO_DATE('11/24/2009 10:24:19', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (300, 5000, TO_DATE('11/25/2009 10:24:20', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (300, 3000, TO_DATE('11/27/2009 10:24:21', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (300, 2000, TO_DATE('11/29/2009 10:24:22', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into SALE
    (EMPNO, SALE_AMT, SALE_DATE)
    Values
    (300, 1000, TO_DATE('11/30/2009 10:24:22', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;
    Any help will be needful for me
    Regards,

    select sale_date,sum(sale_amt) total_sale
    from
    select empno,0 sale_amt,(sale_date + ao.rn) sale_date
    from
    select empno,sale_amt,sale_date ,(t.nxt_dt - t.sale_date) diff
    from
    select empno
    ,sale_amt,trunc(sale_date) sale_date
    ,trunc(nvl(lead(sale_date) over (partition by 1 order by sale_date),sale_date)) nxt_dt
    from sale
    ) t
    where (t.nxt_dt - t.sale_date) >1
    ) rec,(select rownum rn from user_objects where rownum<=200) ao
    where ao.rn <=(rec.diff-1)
    union all
    select empno,sale_amt,trunc(sale_date) sale_date
    from sale
    group by sale_date
    order by 1;
    ~~~~Guess this will serve the purpose...
    Cheers Arpan

  • I am using laptop hitting and slow system not working

    i am using laptop hitting and slow system not working and very late opan file browser every think . plez help me

    Hi,
    Shut down the notebook.  Tap away at the esc key as you start the notebook to enter the Start-up Menu.  Select the Bios option ( usually f10 ) and under the Advanced or Diagnostic tab you should find the facility to run tests on both the Hard Drive and Memory.  Post back with the details of any error messages.
    Note:  If the option to run these tests is not available in the Bios Menu, use the f2 diagnostic menu instead.
    Can you also post back with the following details.
    1.  The full Model No. and Product No. of your notebook - see Here for a guide on locating this information.
    2.  The full version of the operating system you are using ( ie Windows 7 64bit ).
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • My iPhone is split from front panel on top, and back cover of my is swollen too. I am not able to use my phone and I cannot access my data in the phone. Please suggest what could be the cause of this problem?

    My iPhone is split from front panel on top, and back cover of my is swollen too. I am not able to use my phone and I cannot access my data in the phone. Please suggest what could be the cause of this problem?

    It sounds like the battery might have gone bad, and is swelling and causing the symptoms you describe.  Do not attempt to use the phone, but take it to Apple for evaluation.

  • I recently purchased a used ibook g4 and want to update to itunes 10.2. It tells me i need mac os 10.5 to do so. Today is the first day I have ever used a mac and I am not well versed on computers to begin with. What do I need to do?

    I recently purchased a used ibook g4 and i want to update to itunes 10.2. It tells me that I need to update to mac os 10.5.  Today is the fist time that I have ever used a mac and I am not very well versed on computers to begin with. From what I gather I need to purchase the mac os 10.5 but there are a lot of different options and I dont know what I need to do. Can somebody point me in the right direction?  I dont want to spend too much money because i just want my ipod touch to be compatible with my ibook. thank you

    Hi
    Your question is more suitable for the 10.4's General Forum rather than 10.4 OSX Server. Post here instead:
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.4_tiger?categoryID=1 77
    You'll have more of a chance of someone responding.
    HTH?
    Tony

  • When should I use static variable and when should not? Java essential

    When should I use static variable and when should not? Java essential

    Static => same value for all instances of the class.
    Non-static => each instance can have its own value.
    Which you need in which circumstances is completely up to you.

  • The recipient cant see "middle of reply or typing" bubble in imessage. Could it be that I am using iOS 8 and they are not?

    The recipient cant see "middle of reply or typing" bubble in imessage. Could it be that I am using iOS 8 and they are not? Has any of your friends pose this as a minor problem? Is there a setting that I didn't enable?

    ''rojere [[#question-1055991|said]]''
    <blockquote>
    i try to keep my thumb palms off the mouse pad when i am typing but every now and then my screen resizes larger or smaller until i take my left palm off the keyboard base its only when my left palm is resting on the base next to the touch pad. i type pretty fast so it gets annoying and yes it also jumps screens or reverts back to previous message and i have to choose ctrl z to undo and get back to my message i was typing... it also switches tabs on me as well... not sure why my palm being on the left of the keypad on the base should effect anything but it does after a while. and i have to stop what i am doing...and go to the firefox menu and change the screen size back down to 100% sometimes it goes up to 200-300 other times it goes down to 70-80% i find it annoying i i wish there was a way to turn off the screen resize in the setup panel. if its just left to be 100% i am happy with that... i don't need it to be bigger or smaller... there should be a way to LOCK it down... i understand that there are people out there with eye problems and needs to have the screen size increase using the + or - but there should be a lock so it just stays no matter what is happening on my keypad or touch pad or base of the pad... that screen size will not increase or decrease. unless i turn off the lock... perhaps this is something they can implement in the next version or do a quick update of the browser
    </blockquote>
    sorry that is all greek to me thanks for attempting to explain what you were trying to explain sorry i just not tech person to be able to understand or where to begin ... have good day and thanks for again trying

  • Use of UTF8 and AL32UTF8 for database character set

    I will be implementing Unicode on a 10g database, and am considering using AL32UTF8 as the database character set, as opposed to AL16UTF16 as the national character set, primarily to economize storage requirements for primarily English-based string data.
    Is anyone aware of any issues, or tradeoffs, for implementing AL32UTF8 as the database character set, as opposed to using the national character set for storing Unicode data? I am aware of the fact that UTF-8 may require 3 bytes where UTF-16 would only require 2, so my question is more specific to the use of the database character set vs. the national character set, as opposed to differences between the encoding itself. (I realize that I could use UTF8 as the national character set, but don't want to lose the ability to store supplementary characters, which UTF8 does not support, as this Oracle character set supports up to Unicode 3.0 only.)
    Thanks in advance for any counsel.

    I don't have a lot of experience with SQL Server, but my belief is that a fair number of tools that handle SQL Server NCHAR/ NVARCHAR2 columns do not handle Oracle NCHAR/ NVARCHAR2 columns. I'm not sure if that's because of differences in the provided drivers, because of architectural differences, or because I don't have enough data points on the SQL Server side.
    I've not run into any barriers, no. The two most common speedbumps I've seen are
    - I generally prefer in Unicode databases to set NLS_LENGTH_SEMANTICS to CHAR so that a VARCHAR2(100) holds 100 characters rather than 100 bytes (the default). You could also declare the fields as VARCHAR2(100 CHAR), but I'm generally lazy.
    - Making sure that the client NLS_LANG properly identifies the character set of the data going in to the database (and the character set of the data that the client wants to come out) so that Oracle's character set conversion libraries will work. If this is set incorrectly, all manner of grief can befall you. If your client NLS_LANG matches your database character set, for example, Oracle doesn't do a character set conversion, so if you have an application that is passing in Windows-1252 data, Oracle will store it using the same binary representation. If another application thinks that data is really UTF-8, the character set conversion will fail, causing it to display garbage, and then you get to go through the database to figure out which rows in which tables are affected and do a major cleanup. If you have multiple character sets inadvertently stored in the database (i.e. a few rows of Windows-1252, a few of Shift-JIS, and a few of UTF8), you'll have a gigantic mess to clean up. This is a concern whether you're using CHAR/ VARCHAR2 or NCHAR/ NVARCHAR2, and it's actually slightly harder with the N data types, but it's something to be very aware of.
    Justin

  • My document.numbers can not be opened how can i recover the version from yesterday i was not using time machine and it was not in icloud. is there an app i can buy that might help

    my document.numbers can not be opened how can i recover the version from yesterday? i was not using time machine and it was not in icloud. is there an app i can buy that might help

    Thanks Andy,
    I wish I could have told my sister about this as she could not open my homepage back before my new iWeb site. She now can open my site without the yet in case denial window does appear = I thank you.
    I think my iWeb site works as Noone has said otherwise from any platform etc...
    Alex L
    I do agree that should not have to be a consideration for any users so i agree that it would be great if Apple could allow simplicity to run seemlessly.
    I have had this problem since Homepage, and here is
    what has worked for me. I send out the link, and
    then for PC users I send the link with "<" after the address (without quotation
    marks. e.g., <http://site.com>).
    I also put a note that if that doesn't work, to just
    copy and paste the link into a browser. With that I
    have only had 1 person say they still can't open.
    Everyone else gets it to work.
    It's a lot to do and seems like a hassle, but you get
    used to it.
    Hope this helps!
    Andy Martini
    PS - APPLE! When are you going to fix this??! It
    seems like such a small thing yet you guys have been
    stumped for YEARS on this!

  • EXHAUSTED!!! 25 DAYS AND COUNTING FOR INSTALL!

    Well its got to the point where i think ive just about had it with BT im appalled by them now!!!up to now ive been kept well informed as to what's been going on without me having to ring them .Then Last Friday the day that finally i was gonna get my final appointment (the 4th appointment) i was told yet another excuse/reason as to why this wasn't going to happen and that it will take 48 hrs to sort, so tuesday will now be the day i get my appointment, i was then sent a text with a number and to call  if it wasn't sorted by tuesday which is when they were suppose to ring me again with an update but i didn't get the call (the 1ST time)?
    so i called the number i got texted and its the infinity call centre in Dundee well guess what? the problem still persists and that they sent a request but it still hasn't been answered so it could well be another 48 hrs until openreach respond, i asked for a manager to call me back because the person at the call centre was just not bothered atall about my situation and sounded uninterested,well that didn't happen either.
    My MAC code runs out on the 20th that will be a month since i ordered, just over infact!!! i ordered 17th march.And just to add insult to injury my BT account states that the total order was complete on the 7th april(my 3rd appointment date)and they will be taking the 1st month broadband payment off me by DD on the 23rd april. I KNOW ITS HARD TO BELIEVE BUT ITS ALL TRUE!!!
    SO I WARN ANYONE THINKING OF DEALING WITH BT THINK HARD AND LONG???
    days off work,3 engineer appointments,25 days and counting for install,paying for a service i havnt got and uninterested customer services and managers not returning calls.WELCOME TO BT!!!
    WATCHDOG,CISAS,OFFICE OF FAIR TRADING AND THE MAN HIMSELF IAN LIVINGSTON. all getting emails.

    I read through your thread Boostmonkey like you say similar in alot of ways,only i wished id read your thread earlier as i mite have got things done sooner(infact i don't know how i missed it).Ive had some progress today but im not saying anything as im still waitng for some concrete confirmation.
    Good luck with it anyway. let me know how you get on.

  • I just downloaded a few ITunes Apps to my PC using windows 8 and they will not work.  Suggestions?  Thank you.

    I just downloaded a few ITunes Apps to my PC using windows 8 and they will not work.  Suggestions?  Thank you.

    The apps can only be run on an iOS device.   They will not run on your PC.

Maybe you are looking for