Question on Grouping()

I am using Grouping function in one of my select statement.
Now In the statement there is a substr on a particular column within the grouping. If the number of characters to be returned by substr is used as a bind variable then the query returns "not a group by expression" error. Otherwise, if I use any harcoded value instead like 80, then the query works fine.
Can anybody suggest me the reason for this error

Posting your query or at least a simplified version of it would always make this easier. I'm not sure if this is your problem, but I think it is... The column you group by should look exactly the same as it does in the select part of your query. So if your query looks like...
select     substr(column,x,y)
from     table
group by column
...then change it to...
select     substr(column,x,y)
from     table
group by substr(column,x,y)

Similar Messages

  • A few questions about Group Policy development

    This post was originally in the Windows Development forum. Please note the following:
    This question is not about the application and management of GPOs. It's about how to develop a group policy.
    I know about Group Policy Preferences, please do not provide this as an answer.
    I create a custom group policy for an application.
    Recently the application developers allowed settings to be controlled via policy registry keys, in order to make these settings easier to set for Systems Administrators I have created a GPO. Unfortunately, there aren't that many resources
    I can find that help with Group Policy creation, so:
    Is there an easier way to create and edit admx/adml files rather than just a xml editor? Like a GUI front end?
    The vast majority of this applications settings are just a simple Boolean, is there any way to just use one base presentation element for multiple policies? or do I really have to create a presentation element for every single policy? :/
    As mentioned above, most settings are a simple Boolean, but with an additional enforce parameter. If you "enforce" the setting the user is blocked from changing the value. I was going to peg the setting Boolean to whether the policy was
    Enabled or Disabled and have an enforce check box in the policy itself (this would make it easier to just glance at the configured settings and get an idea). Unfortunately, when you disable a policy you cannot interact
    with its contents, so the enforce check box cannot be toggled. So I have two options:
    Have two policies for each setting eg: Disabled: Load printer settings with the document and
    Enabled: ENFORCE Load printer settings with the document
    OR what I have elected to do is just have the one policy with 2 check-boxes in it, one for the setting and one for the enforcement
    The former is both more complex to write for me and more time consuming to configure for the Administrator, the later is easier for me to write but still annoying to use. So my final question is: can I make it so, even though a policy is disabled, you can
    still toggle settings within the policy?

    Hi Thomas.
    > (this will set the default in the application) and then toggling whether
    > that setting is Enforced (unable for the user to modify it - disabling
    > it in the user interface).
    As said - that's not how policies are intended to work - they are always
    enforced. You are talking about preferences that have an optional
    "enforce" switch :) But doesn't matter for the remainder of this post.
    >  1. The presentation table contains hundreds of presentation tags that
    >     essentially are the same thing. From your response there is no way
    >     to make the GPO any easy to write? I can't just create one generic
    >     presentation that multiple policies can use? I have to create a
    >     presentation for every. single. policy.?
    I'd sugggest to use ADM instead of ADMX. Much easier to write and
    maintain, and copy/paste works very well in ADM :)
    https://msdn.microsoft.com/library/bb742499.aspx
    >  2. Because of how the settings are set, as mentioned in my earlier
    >     post, I have chosen to have each policy contain two check boxes.
    >     Each setting could be set to the following:
    >      1. True
    >      2. False
    >      3. True and Enforced
    >      4. False and Enforced
    What elements you need depends on the registry values your application
    is expecting/checking. I'd suggest a radio button (enabled/disabled) and
    a check box "enforced".
    >     there a way for a Disabled policy to also have settings that can be
    >     modified in Group Policy Management? Or can only Enabled policies be
    >     modified?
    You cannot edit what a disabled GPO does, but you can define it
    (VALUEOFF in ADM files if I recall correctly).
    >     well because it would make it easier for them to read the GPO. But I
    >     think you are saying this is not possible.
    Yes, it isn't. It still - at least to me - is a slight misunderstanding
    of "preferences" versus "policies" :)
    Greetings/Grüße,
    Martin
    Mal ein
    gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me -
    coke bottle design refreshment (-:

  • Question regarding grouped Stacks

    Hi,
    I've been searching around for ages and I'm not even sure if this is possible. Essentially I'm trying to make a stacked bar graph that has years across the bottom, and then two bars per year. Each of these bars has two variables. I can't work out how to post an image so I'll do a little conceptual diagram. (N.B. the '---' is simply a way of indenting the text)
    2004
    ---Bar1
    ----Variable A + B
    ---Bar2
    ----Variable C+D
    2005
    ---Bar1
    ----Variable A+B
    ---Bar2
    ----Variable C+D
    Etc...
    I realise I can have variables A B C & D grouped by year if I simply use a bar chart, but I need them stacked as they are percentages i.e. A+B = 100% and I need to show the difference.
    I realise this is probably strangely worded but if anyone could give me any advice on grouped stacked bar graphs I'd be very grateful!
    Thank You!

    Minyall,
    Your question seems to be about getting the total bar length to be 100. So the numbers a & b have to be converted to percents. If a is in cell B5 and b is in C5, the formulas are:
    =A5/(A5+B5)*100
    =B5/(A5+B5)*100
    It's this set of values you want to use in your table.
    pw

  • Questions about Groups Wheel & Admin

    OK I have two systems. One is an iMac upgraded from Leopard to Snow Leopard. Its main hard drive has the following owner & group:
    Owner: "system" (Read & Write)
    Group: "admin" (Read & Write)
    But on my Mac Pro's main drive it is like this:
    Owner: "system" (Read & Write)
    Group: "wheel" (Read & Write)
    Note: The Mac Pro was a clean install of Snow Leopard from the full install disk, whereas the iMac was Leopard upgraded to Snow Leopard.
    I have read in some places that in Snow Leopard they use "wheel" instead of "admin", but why would Apple choose to use such a cryptically named group as "wheel" when the use of a logical, sensical term such as "admin" would be much easier to understand to most users? Why is one Snow Leopard computer using the "admin" group whereas another is using the "wheel" group as the default group for the main hard drive? What is the correct group that the main boot drive should have for it (i.e. when you click on the hard drive on the desktop and do "get info" what should it say)?
    I used Migration Utility to copy a user from my MacBook Pro to the Mac Pro. Then I logged in as Root on the Mac Pro and used this method (http://support.apple.com/kb/HT1428) to rename my user directory to be a new shortname, then create a new user with that shortname and point it at that folder (to fix some nagging permissions issues). Then I deleted the old user account. Then I renamed the new user account folder with the old shortname that it used to have, and created a new user with that name. But every time I create a folder it has the "Wheel" group... which seems like a security problem since anything I download into that folder will now be able to SU. Why would that be the default group?
    In the old OS X (like 10.0, 10.1) there used to be "NetInfo Manager" where you could see all the users on a system and all the groups and change all that stuff, if you wanted to. In Leopard there was "Directory Utility" but it had much more limited features. In Snow Leopard, how do I pull up a list of all the users on a system and be able to edit their groups and all that stuff about them?

    DaddieMac wrote:
    V.K. wrote:
    run the following command in terminal
    sudo chown root:admin /
    you'll have to enter your admin password (which you won't see). that's normal.
    This will change the ownership on the hard drive to root:admin.
    Why can't I just "Get Info" on the drive, and set its group to "admin" in there?
    the whole GUI permissions management in Leopard and Snow leopard is very clunky and leaves a lot to be desired.
    Can I just question why Apple has given us the ability to change the group in the "Get Info" box when really it doesn't do anything, and you still have to resort to using the Terminal and typing in non-plain-English commands that are merely relics of an operating system from 40 years ago that somehow still persists in our basement despite its lack of user friendliness?
    what? SU?? wheel is the superuser group. by default only root belongs to it and nobody else. so having a wheel group on a folder does not create security issues.
    what folders exactly have the wheel group? you home folder? as I said, folders created in any folder will inherit the group of that folder so maybe the wheel on your whole drive is doing this.
    Well, even though I went into the "Get Info" box and took off "Wheel" from my root directory, still, when I make new folders on the root level of the drive, it creates them as being group "Wheel." Now, my understanding is that if I download a program and save it INTO that folder, then it would have the ability to execute as root because it will belong to the "Wheel" group -- am I not understanding this correctly? Thanks.
    as I said, the GUI permission management is all messed up. you just keep running into various messed up aspects of it. this is another one. here is what happens.
    when you remove a group completely from permissions using GUI it does not simply go away. it also incredibly changes to wheel.
    you just don't see it because the permissions for the group are changed to none. so, for example, say, you have a file with the group staff and that group has read permissions to the file. you select that group in GUI permissions panel and use "-" to remove it. what should happen is that the group remains the same but it's permissions are set to 0. what does happen is that the group changes to wheel (which has group id=0) and its permissions are set to 0.
    this is definitely a bug and a silly programming error. It's been around since Leopard. I reported it to Apple a long time ago.
    so despite your hate of terminal and unix you are going to have to use them to fix the issue. get used to it. OS X is unix based and sometimes one has to use terminal to fix things. in this case there is no other way to do this. run the terminal command I gave you and it will fix the problem with new (but not already existing) folders at the top level of the hard drive. if you want to change the group on those you'll need to run similar commands for them too.

  • Index questions for GROUP BY

    1. I have a group by query 'select max(trackingnumber) from xxx group by dsltn'
    What am I supposed to index on, so as to make the query faster - trackingnumber or dsltn.
    2. Also if the query has multiple columns in the group by list
    Eg :- 'select max(trackingnumber) from xxx group by dsltn, vpi, vci'
    ..what should be the nature of the index. Should I create a composite index
    ( like create index x_index on xxx(dsltn, vpi, vci ) )

    Its taking over an hour working on a table of about 12 million records
    "Optimizer"     "Cost"     "Cardinality"     "Bytes"     "Partition Start"     "Partition Stop"     "Partition Id"     "ACCESS PREDICATES"     "FILTER PREDICATES"
    "INSERT STATEMENT"     "ALL_ROWS"     "750609"     "1"     "187"     ""     ""     ""     ""     ""
    "SEQUENCE NIMBUS.PRIMARY_KEY_SEQUENCE"     ""     ""     ""     ""     ""     ""     ""     ""     ""
    "HASH JOIN(RIGHT SEMI)"     ""     "750609"     "1"     "187"     ""     ""     ""     ""A"."TRACKINGNUMBER"="$nso_col_1""     ""
    "VIEW SYS.VW_NSO_1"     ""     "348284"     "4420502"     "57466526"     ""     ""     ""     ""     ""
    "SORT(GROUP BY)"     ""     "348284"     "4420502"     "154717570"     ""     ""     ""     ""     ""
    "TABLE ACCESS(FULL) NIMBUS.CIFINV_IR9"     "ANALYZED"     "285039"     "10850252"     "379758820"     ""     ""     ""     ""     "("SERVICEREQTYPE"='CHANGE' OR "SERVICEREQTYPE"='NEW') AND ("SERVICEREQSUBTYPE"='INITIATE' OR "SERVICEREQSUBTYPE"='MODIFY')"
    "TABLE ACCESS(FULL) NIMBUS.CIFINV_IR9"     "ANALYZED"     "285739"     "12611792"     "2194451808"     ""     ""     ""     ""     ""

  • Question about GROUP BY and HAVING

    Good afternoon,
    I have the following query which returns the desired result (set of students who take CS112 or CS114 but not both). I wanted to "condense" it into a single SELECT statement (if that is at all possible - DDL to execute the statement is provided at the end of this post):
    -- is this select distinct * and its associated where clause absolutely
    -- necessary to obtain the result ?
    select distinct *
      from (
            select s.sno,
                   s.sname,
                   s.age,
                   sum(case when t.cno in ('CS112', 'CS114')
                            then 1
                            else 0
                       end)
                     over (partition by s.sno) as takes_either_or_both
              from student s join take t
                               on (s.sno = t.sno)
      where takes_either_or_both = 1
    ;The following looked reasonable but, unfortunately unsuccessful:
      Window functions not allowed here (in Having Clause)
    select max(s.sno),
           max(s.sname),
           max(s.age),
           sum(case when t.cno in ('CS112', 'CS114')
                    then 1
                    else 0
               end)
             over (partition by s.sno) as takes_either_or_both
      from student s join take t
                       on (s.sno = t.sno)
    group by s.sno
    having sum(case when t.cno in ('CS112', 'CS114')
                    then 1
                    else 0
               end)
             over (partition by s.sno) = 1
    Invalid identifier in Having clause
    select s.sno,
           s.sname,
           s.age,
           sum(case when t.cno in ('CS112', 'CS114')
                    then 1
                    else 0
               end)
             over (partition by s.sno) as takes_either_or_both
      from student s join take t
                       on (s.sno = t.sno)
    group by s.sno, s.sname, s.age
    having takes_either_or_both = 1
    ;I have searched for a document that completely defines the sequence in which the clauses are executed. I have found tidbits here and there but not something complete. I realize that my running into problems like this one is due to my lack of understanding of the sequence and the scope of the clauses that make up a statement. Because of this, I cannot even tell if it is possible to write the above query using a single select statement. Pardon my bit of frustration...
    Thank you for your help,
    John.
    DDL follows.
            /* drop any preexisting tables */
            drop table student;
            drop table courses;
            drop table take;
            /* table of students */
            create table student
            ( sno integer,
              sname varchar(10),
              age integer
            /* table of courses */
            create table courses
            ( cno varchar(5),
              title varchar(10),
              credits integer
            /* table of students and the courses they take */
            create table take
            ( sno integer,
              cno varchar(5)
            insert into student values (1,'AARON',20);
            insert into student values (2,'CHUCK',21);
            insert into student values (3,'DOUG',20);
            insert into student values (4,'MAGGIE',19);
            insert into student values (5,'STEVE',22);
            insert into student values (6,'JING',18);
            insert into student values (7,'BRIAN',21);
            insert into student values (8,'KAY',20);
            insert into student values (9,'GILLIAN',20);
            insert into student values (10,'CHAD',21);
            insert into courses values ('CS112','PHYSICS',4);
            insert into courses values ('CS113','CALCULUS',4);
            insert into courses values ('CS114','HISTORY',4);
            insert into take values (1,'CS112');
            insert into take values (1,'CS113');
            insert into take values (1,'CS114');
            insert into take values (2,'CS112');
            insert into take values (3,'CS112');
            insert into take values (3,'CS114');
            insert into take values (4,'CS112');
            insert into take values (4,'CS113');
            insert into take values (5,'CS113');
            insert into take values (6,'CS113');
            insert into take values (6,'CS114');

    Hi, John,
    Just use the aggregate SUM function.
            select s.sno,
                   s.sname,
                   s.age,
                   sum(case when t.cno in ('CS112', 'CS114')
                            then 1
                            else 0
                       end) as takes_either_or_both
              from student s join take t
                               on (s.sno = t.sno)
           GROUP BY  s.sno,
                    s.sname,
                  s.age
           HAVING  sum(case when t.cno in ('CS112', 'CS114')
                            then 1
                            else 0
                       end)  = 1;Analytic functions are computed after the WHERE- and HAVING clause have been applied. To use the results of an analytic fucntion in a WHERE- or HAVING clause, you have to compute it in a sub-query, and then you can use it in a WHERE- or HAVING clause of a super-query.

  • LR 1.4 Question about Group Edit Capture Time

    Hey guys... working my way through...
    Was wondering -- when I highlight a group of files -- and then go to the Metadata Menu and choose "Edit Capture Time" -- why doesn't it change the date of all the High-Ligghted Photos?
    I am obviously doing something wrong... Can someone please tell me who to di it right?
    THANKS!!

    ambienttroutmask wrote:
    It's a while since I used LR 1, but I think it was the same....to write time changes to RAW files, other than DNG's, you need to enable this in catalog settings. in metadata write changes into propitiatory RAW files. LR is very reluctant to write anything into propitiatory files (and rightly so), best to convert them to DNG's.
    actually - i'm kinda confused.
    all my images are DNG's.
    All I want to do is take a group of photos I took in 2002 [that all have bad dates from different decades somehow] and correct a group of say 130 files at a time to a specific day from all the various days they are mistakenly showing in Capture Time.
    But when I highlight a group of say 30 files and choose to EDIT CAPTURE TIME -- only 1 or maybe a couple of files change -- the rest stay.
    iPhoto allowed me to Batch Change a group of photos from various dates to 1 single date -- but I am getting the impression LR 1.4 does not have the ability to do this.

  • Question about grouping.

    Hello ,
    I have a problem in grouping my data the way i want , i have 2 tables : Orders & Modifiedorders ,
    the Modifiedorders holds the orderid and some data about how the order is modified , sometimes the orderid
    in the Modifiedorders table can repeat if the data modified is of different types , like modify the quantity or price ..
    Now what i want is to make a report that displays some data from the Orders table and when there are
    record(s) from the modifiedorders table it should be displayed at the left for example , but without repeating the orderid .
    What i tried is creating an outerjoin query between the 2 tables , and using the wizard i created a report with the group left style and had the Orderid as the grouping field , but still the orderid repeats . what should i do ?
    Thanks in advance..

    What i tried is creating an outerjoin query between the 2 tables , and using the wizard i created a report with the group left style and had the Orderid as the grouping field , but still the orderid repeats . what should i do ?You did the right thing. Reuse Reports Wizard.
    What's your query?

  • Quick question about GROUP BY

    Hello guys,
    I was wondering if anybody can shed the light on this? It's not very important. I'm just being curious here.
    Imagine I have the following table:
    CREATE TABLE my_table
      n NUMBER(15)
    INSERT INTO my_table SELECT level FROM dual CONNECT BY LEVEL <= 10;I know I can do this
    SELECT 'MY_TABLE',
           (SELECT COUNT(*) FROM my_table)
      FROM dual;To get the name of the table and how many records the table has. Because DUAL table has only one record it will return the correct result.
    But I don't understand why the following query returns the correct result:
    SELECT 'MY_TABLE',
           (SELECT COUNT(*) FROM my_table)
      FROM my_table
    GROUP BY NULL;If I remove the GROUP BY clause, I will have 10 records because my original table has 10 records. But how is it possible to GROUP BY NULL? Actually, you can group by on anything (1, 'HELLO'...) and it will return the correct result.
    So, can anyone tell me how does this make sense??
    Thanks in advance,

    Hi,
    user13117585 wrote:
    Hello guys,
    I was wondering if anybody can shed the light on this? It's not very important. I'm just being curious here.
    Imagine I have the following table:
    CREATE TABLE my_table
    n NUMBER(15)
    INSERT INTO my_table SELECT level FROM dual CONNECT BY LEVEL <= 10;I know I can do this
    SELECT 'MY_TABLE',
    (SELECT COUNT(*) FROM my_table)
    FROM dual;To get the name of the table and how many records the table has. Because DUAL table has only one record it will return the correct result.The fact that dual has only one row explains why the result set has one row. How many columns and what is in those columns doesn't depend on dual in any way.
    But I don't understand why the following query returns the correct result:
    SELECT 'MY_TABLE',
    (SELECT COUNT(*) FROM my_table)
    FROM my_table
    GROUP BY NULL;If I remove the GROUP BY clause, I will have 10 records because my original table has 10 records. But how is it possible to GROUP BY NULL? Actually, you can group by on anything (1, 'HELLO'...) and it will return the correct result.
    So, can anyone tell me how does this make sense??Right. "GROUP BY x" means the output will have 1 row for each distinct value of x. (NULL is treated like a value in this case.) So how many distinct values of NULL are there, or how many distinct values of 1, or 'HELLO', or any constant? There's only 1 value, constants, as the name implies, never change values. So if you GROUP BY any constant, the result set will have exactly one row.
    Thanks in advance,

  • Question on Group account number in FS00

    when I try to create G/L account FS00, I see the group account number as required entry. I want to either
    1) Not display group account number field in FS00 screen
    or
    2) Make it as optional entry.
    Can anyone help me on this. Thanks for your help.
    Shalini.

    Hi,
    While creating your chart of accounts in OB13,you have assigned the group chart of accounts....in OB13 take off the group chart of accounts and save...again try to create the GL account.....it should resolve
    TY
    Aravind
    Assign points if useful

  • Quick question - which group owns this file? -rw-r--r--@ 1 admin -  Daemon?

    As per subject line. if i type "id 1" in terminal the uid is daemon - meaning admin is the group - is this correct? If it is - why is one part of the result a uid and one a name? Why the @?
    -rw-r--r--@ 1 admin 1656
    (It's a script by the way)

    It's hard to say since it looks like the line was typed in (as opposed to copied and pasted), and the line doesn't appear to be complete (I'm assuming it's the output of 'ls -l').
    But actually, going by position, the "1" is the number of links - and since your system has a user with 'uid=1' configured ('daemon'), then ls -l should list the name rather than the number, so the "1" probably is the number of links rather than the "owner".
    Then that would make the file's owner "admin" (which is very odd - try 'id admin'), and the group an undefined numerical value, representing the 'gid=1656'. Or else it's the size and a column is missing from the post.
    The "@" means the file has extended attributes (see the 'man" page for 'ls'). You can also try 'ls -l@ filename' or 'xattr -l filename'

  • Question on Group Membership issue in installation

    Hi,
    I am installing the Oracle DB and got this error in the 'Prerequisite Checks':
    'Group Membership: <GroupName>
    This is a prerequisite condition to test where user "<userID>" is a member of the group "<GroupName>"

    SD wrote:
    Hi,
    I am installing the Oracle DB and got this error in the 'Prerequisite Checks':
    'Group Membership: <GroupName>
    This is a prerequisite condition to test where user "<userID>" is a member of the group "<GroupName>"consider reading & following the Installation Guide found at http://tahiti.oracle.com

  • Design question: Change Group membership for a AD resource via SelfService

    Hi all,
    based on the OIM tutorials, I designed OIM that way that an end user can successfully request a resource. Is there a way to allow end users to modify their resource "subscriptions"? For example, I would like to allow end users to change their AD group memberships after the initial provision to the resource.
    From what I have learned from the tutorials, I would assume to create an AD group membership attribute in the user account profile form and propagate changes to that attribute back to AD.
    Or is there a way to allow end users to change their resource data directly under "My Resources" ?

    there is no concept of requesting a modification of an already provisoned account. Like you said this can be achieved thru an attribute on the user's profile and on changing that attribute, downstream applications can be propagated the new value.
    Typically if changes to an already proviisoned account needs to be done in oim and through oim, an oim admin goes to the user's resource profile and clicks on edit on the process form and can edit any data there. in case of ad groups, there will be a child process form that shows the groups that the user is a member of, you can insert(add) new groups or delete existing groups from there and save the form. In the proviisoning porcess of AD you will need to write a porcess task, which should add/remove the user from the specified group in AD on the trigger when a new group is added or an existing group is removed wehn the admin is modifying the user's AD process form/process child forms in oim.

  • A tricky question on Grouping sets....

    Hi All,
    I have a weird requirement and table as folows:
    Per_strt        Per_end     Per_desc        empid   Combo       sales
    1-Dec-2008      1-Dec-2008  Day             1000    1           100
    1-Dec-2008      1-Dec-2008  Day             1000    2           200
    2-Dec-2008      2-Dec-2008  Day             1000    1           100
    2-Dec-2008      2-Dec-2008  Day             1000    2           200
    31-Dec-2008     31-Dec-2008  Day            1000    1           100
    31-Dec-2008     31-Dec-2008  Day            1000    2           200
    1-Dec-2008      31-Dec-2008  Month          1000    1           1000
    1-Dec-2008      31-Dec-2008  Month          1000    2           2000
    1-Jan-2009      1-Jan-2009  Day             1000    1           100
    1-Jan-2009      1-Jan-2009  Day             1000    2           200
    2-Jan-2009      2-Jan-2009  Day             1000    1           100
    2-Jan-2009      2-Jan-2009  Day             1000    2           200
    31-Jan-2009     31-Jan-2009  Day            1000    1           100
    31-Jan-2009     31-Jan-2009  Day            1000    2           200
    1-Jan-2009      31-Jan-2009  Month          1000    1           1000
    1-Jan-2009      31-Jan-2009  Month          1000    2           2000
    1-Feb-2009      1-Feb-2009  Day             1000    1           100
    1-Feb-2009      1-Feb-2009  Day             1000    2           200
    2-Feb-2009      2-Feb-2009  Day             1000    1           100
    2-Feb-2009      2-Feb-2009  Day             1000    2           200
    28-Feb-2009     28-Feb-2009  Day            1000    1           100
    28-Feb-2009     28-Feb-2009  Day            1000    2           200
    1-Feb-2009      28-Feb-2009  Month          1000    1           1000
    1-Feb-2009      28-Feb-2009  Month          1000    2           2000
    ------------------------------------------------------------------------------------------------Now I want to generate a Year to Date record for Feb for the current year for each of employees for each combo
    Also a weekly row for each week and here the issue is week can cross year and months
    Per_strt        Per_end         Per_desc        empid   Combo       sales
    01-Jan-2009     28-Feb-2009     Year            1000    1           6000
    01-Jan-2009     28-Feb-2009     Year            1000    2           6000
    26-Dec-2008     02-Jan-2009     Week            1000    1           1500
    26-Dec-2008     02-Jan-2009     Week            1000    2           2500similiarly a YTD for Jan and similiarly for other weeks..... The start of the week is considered to be sundays and end on saturdays
    Thanks and Regards,
    Saff
    How to achieve this using a single query?

    The first week 2009 : start 28-12-2008    end : 03-01-2009
    Solution
    select *
    from  T
    model
    return updated rows
    partition by (empid,combo,case when per_desc='Day' then   TO_char(per_strt+1,'iw')  else '99' end as  pp, case when  to_char(PER_STRT,'mm')='12' and  TO_char(per_strt+1,'iw')='01'  then extract( year from PER_STRT) +1 else extract( year from PER_STRT)  end   yy )
    dimension by(row_number()over(partition by empid,combo,case when per_desc='Day' then   TO_char(per_strt+1,'iw') else '99' end  order by PER_STRT) rn)
    measures(PER_STRT, PER_END,PER_Desc, sales somme)ignore nav
    rules
    upsert
    iterate(100)
    until(presentv(PER_STRT[iteration_number+2],1,0)=0)
    ( somme[0]=somme[0]+somme[iteration_number+1],
    PER_Desc[0]=case when PER_Desc[iteration_number+1] ='Day'  then 'Week' else 'Year'  end ,
    PER_STRT[0]=min(PER_STRT)[any],
    PER_end[0]=max(PER_end)[any]  )
    order by empid,combo,PER_Desc,per_strt
    /To resolve the problem to_char(sysdate,'iw') you just put to_char(sysdate+1,'iw') = First day of the week is sunday
    SQL> edit
    Wrote file afiedt.buf
      1*  select to_char(to_date('2008-12-27','yyyy-mm-dd')+1,'iw') from dual
    SQL> /
    TO
    52
    SQL> select to_char(to_date('2008-12-28','yyyy-mm-dd')+1,'iw') from dual;
    TO
    01
    SQL> select to_char(to_date('2008-12-29','yyyy-mm-dd')+1,'iw') from dual;
    TO
    01
    SQL>  select to_char(to_date('2008-12-26','yyyy-mm-dd')+1,'iw') from dual;
    TO
    52
    SQL>  select to_char(to_date('2008-11-30','yyyy-mm-dd')+1,'iw') from dual;
    TO
    49
    SQL> select to_char(to_date('2009-01-03','yyyy-mm-dd')+1,'iw') from dual;
    TO
    01
    SQL> select to_char(to_date('2009-01-04','yyyy-mm-dd')+1,'iw') from dual;
    TO
    02
    SQL>
    DEmo
    SQL> select * from t order by empid,combo,PER_Desc,per_strt;
    PER_STRT  PER_END   PER_D      EMPID      COMBO      SALES
    01-DEC-08 01-DEC-08 Day         1000          1        100
    02-DEC-08 02-DEC-08 Day         1000          1        100
    28-DEC-08 28-DEC-08 Day         1000          1        500
    29-DEC-08 29-DEC-08 Day         1000          1         50
    31-DEC-08 31-DEC-08 Day         1000          1        100
    01-JAN-09 01-JAN-09 Day         1000          1        100
    02-JAN-09 02-JAN-09 Day         1000          1        100
    30-JAN-09 30-JAN-09 Day         1000          1        500
    31-JAN-09 31-JAN-09 Day         1000          1        100
    01-FEB-09 01-FEB-09 Day         1000          1        100
    02-FEB-09 02-FEB-09 Day         1000          1        100
    PER_STRT  PER_END   PER_D      EMPID      COMBO      SALES
    28-FEB-09 28-FEB-09 Day         1000          1        100
    01-DEC-08 31-DEC-08 Month       1000          1       1000
    01-JAN-09 31-JAN-09 Month       1000          1       1000
    01-FEB-09 28-FEB-09 Month       1000          1       1000
    01-DEC-08 01-DEC-08 Day         1000          2        200
    02-DEC-08 02-DEC-08 Day         1000          2        200
    31-DEC-08 31-DEC-08 Day         1000          2        200
    01-JAN-09 01-JAN-09 Day         1000          2        200
    02-JAN-09 02-JAN-09 Day         1000          2        200
    31-JAN-09 31-JAN-09 Day         1000          2        200
    01-FEB-09 01-FEB-09 Day         1000          2        200
    PER_STRT  PER_END   PER_D      EMPID      COMBO      SALES
    02-FEB-09 02-FEB-09 Day         1000          2        200
    28-FEB-09 28-FEB-09 Day         1000          2        200
    01-DEC-08 31-DEC-08 Month       1000          2       2000
    01-JAN-09 31-JAN-09 Month       1000          2       2000
    01-FEB-09 28-FEB-09 Month       1000          2       2000
    27 rows selected.
    SQL> select *
      2  from  T
      3  model
      4  return updated rows
      5  partition by (empid,combo,case when per_desc='Day' then   TO_char(per_strt+1,'iw')  else '99' e
    nd as  pp, case when  to_char(PER_STRT,'mm')='12' and  TO_char(per_strt+1,'iw')='01'  then extract(
    year from PER_STRT) +1 else extract( year from PER_STRT)  end   yy )
      6  dimension by(row_number()over(partition by empid,combo,case when per_desc='Day' then   TO_char(
    per_strt+1,'iw') else '99' end  order by PER_STRT) rn)
      7  measures(PER_STRT, PER_END,PER_Desc, sales somme)ignore nav
      8  rules
      9  upsert
    10  iterate(100)
    11  until(presentv(PER_STRT[iteration_number+2],1,0)=0)
    12  ( somme[0]=somme[0]+somme[iteration_number+1],
    13   PER_Desc[0]=case when PER_Desc[iteration_number+1] ='Day'  then 'Week' else 'Year'  end ,
    14  PER_STRT[0]=min(PER_STRT)[any],
    15  PER_end[0]=max(PER_end)[any]  )
    16  order by empid,combo,PER_Desc,per_strt;
         EMPID      COMBO PP         YY         RN PER_STRT  PER_END   PER_D      SOMME
          1000          1 49       2008          0 01-DEC-08 02-DEC-08 Week         200
          1000          1 01       2009          0 28-DEC-08 02-JAN-09 Week         850
          1000          1 05       2009          0 30-JAN-09 31-JAN-09 Week         600
          1000          1 06       2009          0 01-FEB-09 02-FEB-09 Week         200
          1000          1 09       2009          0 28-FEB-09 28-FEB-09 Week         100
          1000          1 99       2008          0 01-DEC-08 31-DEC-08 Year        1000
          1000          1 99       2009          0 01-JAN-09 28-FEB-09 Year        2000
          1000          2 49       2008          0 01-DEC-08 02-DEC-08 Week         400
          1000          2 01       2009          0 31-DEC-08 02-JAN-09 Week         600
          1000          2 05       2009          0 31-JAN-09 31-JAN-09 Week         200
          1000          2 06       2009          0 01-FEB-09 02-FEB-09 Week         400
         EMPID      COMBO PP         YY         RN PER_STRT  PER_END   PER_D      SOMME
          1000          2 09       2009          0 28-FEB-09 28-FEB-09 Week         200
          1000          2 99       2008          0 01-DEC-08 31-DEC-08 Year        2000
          1000          2 99       2009          0 01-JAN-09 28-FEB-09 Year        4000
    14 rows selected.
    SQL> Regards
    Salim.

  • Data Gathering Application - Architecture Question

    I'm working on revising an existing application that's used to collect data gathered by users from various sources (various computer systems, paper files, discussions/interviews with other employees, etc.) which is then used for analysis and reporting of level of compliance with mandates at various levels (overall, location, individual).
    The existing application gathers data via two basic form types: one is for a specific individual having multiple data points; the other is for everyone in the location with multiple data points. For example, type 1 looks like:
    Person
    Question 1 Response 1
    Question 2 Response 2
    Question N Response N
    While the Type 2 form looks like:
    Location
    Person 1 Question 1 Question 2 ... Question N
    Person 2 Question 1 Question 2 ... Question N
    Person N Question 1 Question 2 ... Question N
    The questions are grouped by types of information being analyzed, so that those questions appear on different pages and may apply to different sets of individuals or locations. Not all locations are required to gather information on the same questions, depending on their compliance level last year. So, location A may have to answer questions 1, 2 and 3, while location B may answer questions 1, 3 and 4.
    My question is this: The table used to store the data is structed like:
    Person ID, location, page, q1, q2, ..., qN
    To continue the above example of locations A and B, both locations would store the responses in columns q1, q2, and q3 since they had three questions that applied to them. We can then reconstruct which question the response applies to by checking which questions applied to the location. We're using the apex api in the query to generate select-list items for the questions with the valid responses for each question (some are yes/no, others allow NA, a number 1-3, or a typed-in positive integer for a couple of questions).
    Since we need to maintain the data from two forms (either for an individual or for all individuals at a location), would it be easier to maintain in APEX using a table that stores each question in a separate row?
    PersonID, location, Page, question, response
    Further, we want to simplify the application which currently uses a separate page for each item type which is customized to the max number of questions for that page for the year. Instead we want to make a more generic set of pages that can at least handle an arbitrary number of items or, ideally, however many questions may be applicable in the future. While we can assume that the practical upper limit would be 30 questions, in the future it is possible we could be mandated to ask several times that number, maybe 100 or more.
    The main goal is to make the application robust to handle the questions consistenly, no matter how many are defined for a type and no matter how many are required for the selected individual or location.
    I'm already working on the page simplification process by replacing literals with session-state and application items, and realize that to make the pages robust we'll have to convert from static queries to generating the query from plsql using generic columns for the report in APEX.
    If anyone could share their thoughts/experience with this type of application, your input is greatly appreciated.
    Thanks,
    Richard

    Hi Richard,
    I find it bad practice to make a table PersonId, location, page, q,q1 .. qN
    it will do more harm in analysing the data than you will benefit in collecting the information.
    In my opinion you should normalize it a bit more. Seperate table for Person, with it's attributes. and if it is a 1 to 1 relation, also an locationId. Then a seperate table to hold the location information. Then you are having questions and awnsers. based on compliance level of the location persons may answer these questions. So in my opinion, youre location-table will have an attribute 'compliance_level' and in the question table also an attribute, like minimum compliance level. so this could be an criteria for showing questions or not.
    To register the answers done bij a person, also an awnser-table will be nesseccary, with relation to the specific question and the personId who answer it. Because of the 1 to 1 relation between person and location, this information does not have to be registerd with the anwsers.
    so in short:
    5 tables =>
    Person (id, name, locationId, etc. )
    Location (id, locationName, complianceLevel)
    Question(id, quetion, minCompliance)
    Anwser(id, questionId, personId, answerId)
    In order to create these forms, i guess a master-detail form will be in place. where for one master (person in this case), the details can be shwon (question) in a tabular form with input for the answers.
    hope this will help!

Maybe you are looking for

  • MacBook Pro 13 early 2011 repeated unexpected shut down

    This machine has had problems for 6 months or so, spontaneous shutdowns and automatic restarts.  It's been back to Apple twice: first time a cable change, the second a new logic board.  The HD and memory have been changed.  SMC has been reset.  It's

  • Scenario – Third Party PO:  Message Number KI235.

    Dear All, We are in the process of upgrading our client SAP system from ECC 5.0 Non Unicode Upgrade to ECC 6.0 EhP 5 Unicode. The upgrade has happened upto the Quality system where the testing process is underway. We are getting error message while c

  • 2 Dual core intel xeon vs quad core. Whats the difference??

    I came across someone who's selling his mac pro 1.1 (aprox 2-3 years old machine) which hosts 2 dual core intel xeon processors 2.66 Ghz (4 total cores) with an L2 cache of 4 MB per processor and 3 gb of RAM. He is asking for 1200.00 I wonder: 1. is

  • I am still having problems with wi fi connectivity after I upgraded my computer to os x 10.9.4.

    I updated my laptop to 10.9.4, and now my laptop won't continually stay connected to the internet. I will get it to open a page initially, then when I try another page, the browser acts like it's going to load a page, but then just hangs there. When

  • Photoshop CS4 can't save as Photoshop PDF

    I am trying to save a multi-layer Photoshop CS4 document as a Photoshop PDF file with embedded color profile. Everything is set to the default except for compatibility which I set as Acrobat 5 (PDF 1.4) . The progress bar for writing the file proceed