Query to get the numbers and percent by date range

11g version.

Hello

I have the following data in the format
Opty_Id        creation_date               user          accepted_flag 

1         01-mar-2013                  ryan                  N
2         02-mar-2013                  sam                   Y
3         02-mar-2013                  ryan                   Y
.
.
.
I want to get all the charges and % of all users who have accepted_flag the value n. basically, users who have not yet accepted in the format of Opty_id.
ageing             count        Percentage
0-20 days          1                 10%(this will offcourse depend on the total number of opty id and then out of that how many did not accept within the given period.
21-40 days        0                  0%
41-60 days        0                  0%
The column of aging is creation_date, basically, how much body id, were created between now and 20 days, 21-40 and 41-60 days and have not yet accepted (accept the flag = N)


Any help please.

Thank you
Ryan

I get other results

with t as (select 1 as opty_id, to_date('01/03/2013','DD/MM/YYYY') as date_created, 'ryan' as auser, 'N'  as accepted_flag from dual union all
           select 2, to_date('02/03/2013','DD/MM/YYYY'), 'sun', 'Y' from dual union all
           select 3, to_date('03/02/2013','DD/MM/YYYY'), 'sun', 'Y' from dual union all
           select 4, to_date('02/01/2013','DD/MM/YYYY'), 'ryan', 'N' from dual union all
           select 5, to_date('03/01/2013','DD/MM/YYYY'), 'tom', 'Y' from dual)

select
 decode(grp,1,0,grp*20-19)
 ||'-'||
 grp*20
 ageing
,sum(case accepted_flag when 'N' then 1 else 0 end) count
,sum(case accepted_flag when 'N' then 1 else 0 end)
/sum(sum(case accepted_flag when 'N' then 1 else 0 end)) over () Percentage
from
(select
 ceil(decode((trunc(sysdate) - date_created),0,1,trunc(sysdate) - date_created)/20) grp
,date_created
,accepted_flag
from  t
)
group by
grp

AGEING     COUNT     PERCENTAGE
"0-20"     "1"     "0,5"
"21-40"     "0"     "0"
"41-60"     "0"     "0"
"61-80"     "1"     "0,5"

Published by: chris227 on 04.03.2013 03:41
Modified according to response below

Tags: Database

Similar Questions

  • get the month and year of date type

    Hi all
    I need to get the month and year of type date.

    For example
    select to_date('2011-01-17', 'yyyy-mm-dd') from dual;
    Required result:
    01-2011
    Any ideas?

    Thanks in advance,
    Bahchevanov.
    select to_char(to_date('2011-01-17', 'yyyy-mm-dd'),'mm-yyyy') from dual;
    

    HTH

  • SQL query to get the numbers from 0 to 99

    How can we write a sql query to get values from 0 to 99... This should not come from any table
    SELECT LEVEL - 1
      FROM  DUAL
      CONNECT BY LEVEL <= 100
    /
    

    SY.

  • How can I get the numbers and the name of the piece?

    How can I get a # and compatibility for Pavillion DV7-4065dx parts list.

    Especially need to get low basic coverage.

    Your interview Guide & list includes:

    http://h10025.www1.HP.com/ewfrf/wc/manualCategory?cc=us&DLC=en&LC=en&product=4221673&task=&

  • Query to get the data of the column and the metadata in the same set of results.

    Is it possible to build a query to get the values of the columns in a table and also be able to get some metadata (data type, data_length, data_precision, data_scale) for columns in the same set of results.

    If I use a join, have a common value to join on the two tables?

    you use a cross join, not requiring common values.

    create table T (n number, d date, v varchar2(30));
    insert into T values (1,sysdate,'ABC');
    commit;
    
    select C.column_name, c.data_type, c.data_length,
    case c.column_id
     when 1 then to_char(T.N)
     when 2 then to_char(T.D)
     when 3 then T.V
    end VALUE
    from USER_TAB_COLUMNS C, T
    where C.table_name='T'
    order by c.column_id;
    
  • SQL query to get the NULL records after the last matching flag

    I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).

    SQL > create table xx1

    2 (identification number,

    3 flag varchar2 (10));

    Table created.

    SQL > insert into xx1 values (1, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (2, null);

    1 line of creation.

    SQL > insert into values xx1 (3, null);

    1 line of creation.

    SQL > insert into xx1 values (4, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (5, null);

    1 line of creation.

    SQL > insert into xx1 values (6, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (7, null);

    1 line of creation.

    SQL > insert into values xx1 (8, null);

    1 line of creation.

    SQL > insert into values xx1 (9, null);

    1 line of creation.

    SQL > select * from xx1.

    FLAG OF THE ID

    ---------- ----------

    1. IS

    2

    3

    4. IS

    5

    6. IS

    7

    8

    9

    9 selected lines.

    SQL >

    Hello

    user11164339 wrote:

    Hi Frank - when I run the query, I don't see the results data.

    I get

    FLAG OF THE ID

    ----- ----------

    7

    8

    9

    What you do differently?

  • Query to find the Pages and the list of permissions associated with a particular role in PS

    I want a query to find the Pages and the list of permissions associated with specific roles in PS.

    For example, if we see the role of manager accounts payable, it conatins Pages and the list of permissions.

    But, to get everything in EXCEL sheet by Manuel priocess's BIG job. So, can someone give me the query.

    Please try under queries

    The roles assigned to the list of Perm:

    SELECT B.ROLENAME

    OF PSCLASSDEFN A, PSROLECLASS B

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1).

    List of Perm pages can access:

    SELECT B.MENUNAME, B.BARNAME, B.BARITEMNAME, B.PNLITEMNAME, C.PAGEACCESSDESCR, B.DISPLAYONLY

    OF PSCLASSDEFN A, PSAUTHITEM B, PSPGEACCESSDESC C

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1

    AND B.BARITEMNAME > ' '

    AND B.AUTHORIZEDACTIONS = C.AUTHORIZEDACTIONS)

  • IOM sql Query to get the status of the failed task

    Hello world

    We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.

    Thanks in advance.

    Kind regards
    MKN

    Hello
    Use this query to get the status of the task, also check the cooments

    SELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
    OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
    WHERE OSI.MIL_KEY = MIL.MIL_KEY
    AND ANN. SCH_KEY = OSI. SCH_KEY
    AND STA. STA_STATUS = SCH. SCH_STATUS
    AND TOS. PKG_KEY = PKG. PKG_KEY
    AND MIL. TOS_KEY = TOS. TOS_KEY
    AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
    AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
    AND OST. OBJ_KEY = OBJ. OBJ_KEY
    AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
    AND OBJ. OBJ_NAME = "User AD".
    AND OST. OST_STATUS = "Provisioning" - filter accordinglly
    AND STA. STA_BUCKET = 'pending' - filter accordinglly
    AND PKG. PKG_NAME = "AD User" - filter accordinglly
    AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
    ;
    Thank you
    Kuldeep

  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • How do I get the toolbar and the sidebar to display in the Finder?

    How do I get the toolbar and the sidebar to display in the finder window? The choices are grayed out in the view.

    Hello!

    You clicked on dock finder, take the cursor to the top and clicked on display and then click on hide menu bar .it toolbar is hidden.

    See the side bar, tool bar again click on view - once again, click Show toolbar.

    Thank you!

  • How to get the phone and messages back in my dock apps? And for some reason, I discover now all my app pages from the middle of my phone and not at the top?

    How can I get the phone and messages apps in my dock? And for some reason, I discover now all my app pages from the middle of my phone and not at the top?

    Try

    Settings > general > reset > reset home screen presentation.

    Note: All other applications will be organised by alphabetical order.

  • I've lost the last two digits of my valid key for xp pro sp2 and notebook, how do I get the key and support? where?

    I've lost the last two digits of my valid key for xp pro sp2 and notebook, how do I get the key and support? where?

    Hi Jonathan,.

    Please go to the Microsoft Community Forums.
    After the description of the question, I understand that you have lost the last 2 digits of the product key.
    Let me go ahead and help you with the issue.
     
    Please answer these questions, which will help us to help you best.
    1. How did you get the product key?
    2. the operating system come preinstalled on the computer?
     
    I suggest you for the link and check if that helps:
    How to identify, locate, and replace a product key
     
    See also:

    I hope this helps. If you have any other queries/issues related to Windows, write us and we will be happy to help you further.
  • Get the name and the data type into an object?

    Hello

    I would like to know if there is a way to get the names and the types of data encapsulated in an object of labview?

    For example, let's say I make a simple object, called myObject to be commonplace, with private data: myObjectName (string), myObjectValue (int 32) (etc.)

    So, how to build a method to return the type of the data of myObjectValue, or infact back the names and types of all data in the object field, which could be a lot?

    Thank you

    Paul.


  • How to get the scanning and fax utilities works from 2840 printer. Print function works from pc

    I changed my google chrome browser and I finally got my confiquered pc and printer. He is an all-in-one 2840 color laser jet. How do I get the scan and fax utilities to perform?

    It is useful to include the manufacturer and model number.

    What version of Windows you have, including the service pack?

    How the device is connected to your computer (USB, Ethernet, other)?

    Have you installed the software that came with your HP Color LaserJet 2840 AiO printer?

    If not, why?  If you did, what error messages you are seeing?  Please report messages completely, without paraphrasing.

    Start here: HP Color LaserJet 2820 and 2840 AiO products Series - first installation and install

  • When I open Windows mail, I start to get the mail and I get it about 474 243. And then an error saying Windows mail will be closed because of an error.

    Windows mail - error and the same letter over and over again.

    When I open Windows mail, I start to get the mail and I get it about 474 243. And then an error saying Windows mail will be closed because of an error. And I start it again and I get the SAME email AGAIN, and again, it stops somewhere and closes.

    Anyone know what could be the problem?

    You can try to set up a new e-mail account and use the exact settings of the account that you have now.  This way, you will have a copy of the same account.  Then see if it has the same problem.  If it works and is not old, and then see if the old man works after this and remove one of them, if you do not receive the messages in doubles.

    If the new copy of account has the same problem, then it's a stuck message and your courier company should fix this.

    Steve

Maybe you are looking for