The combination of queries? (division)

{color: #000080} I have two queries what results I use to get the rate or percentage. Here they are: {color}



< pre >
SELECT
COUNT (hd. ENTRY_ID)
Of
HPD_HELP_DESK_ASSIGNMENT_LOG,
HPD_HELP_DESK hd,
CTM_SUPPORT_GROUP ResolvedByGroup,
CTM_SUPPORT_GROUP,
CTM_SUPPORT_GROUP_ASSOC_LOOKUP
WHERE
HD. REPORTED_DATE & gt; = ((SYSDATE-TO_DATE (' 01/01/1970 00:00:00 ',' JJ-MM-AAAA HH24:Mi:SS')) * (24*60*60))-(24*60*60) reported 24 past hours. < br / > AND < br / > (hd.)) ASSIGNED_GROUP = "SERVICEDESK" GOLD hd. ASSIGNED_GROUP = "Z-SERVICEDESK") < br / > AND (hd. RESOLVED_BY_GROUP = "SERVICEDESK" GOLD hd. RESOLVED_BY_GROUP = "Z-SERVICEDESK") < br / > AND hd.resolved_by_group = hd.assigned_group < br / > AND hd.total_transfers = 0 < br / > AND (hd. LAST_RESOLVED_DATE - hd. REPORTED_DATE) & lt; (60 * 60 * 1) resolved in 1hours
AND hd. AUTHOR = hd. ASSIGNEE_LOGIN_ID
AND hd. SERVICE_TYPE = 0

AND
(HPD_HELP_DESK_ASSIGNMENT_LOG. INCIDENT_ENTRY_ID ()) = hd. ENTRY_ID)
AND (CTM_SUPPORT_GROUP_ASSOC_LOOKUP. Login_id = hd. TRANSMITTER)
AND (CTM_SUPPORT_GROUP_ASSOC_LOOKUP. DEFAULT_X = 0)
AND (CTM_SUPPORT_GROUP. SUPPORT_GROUP_ID (+) is hd. ASSIGNED_GROUP_ID)
AND (hd. RESOLVED_BY_GROUP = ResolvedByGroup.SUPPORT_GROUP_NAME (+))
AND
(
CTM_SUPPORT_GROUP_ASSOC_LOOKUP. SUPPORT_GROUP_NAME in ('service DESK', "Z-SERVICEDESK")
AND
TRUNC (hd. REPORTED_DATE / 86400 + TO_DATE('12/31/1969 5:00:00 PM','MM/DD/YYYY HH:MI:SS AM')) BETWEEN to_date (October 28, 2008 ', 'dd-mm-yyyy') AND to_date (October 28, 2008 ', 'dd-mm-yyyy')
)
< / pre >

{color: #000080}

and {color}



< pre >
SELECT
COUNT (hd. ENTRY_ID)
Of
HPD_HELP_DESK hd,
CTM_SUPPORT_GROUP_ASSOC_LOOKUP
WHERE
HD. REPORTED_DATE & gt; = ((SYSDATE-TO_DATE (' 01/01/1970 00:00:00 ',' JJ-MM-AAAA HH24:Mi:SS')) * (24*60*60))-(24*60*60) - reported past 24 hours.)) < br / > AND hd. SERVICE_TYPE = 0 < br / > AND (CTM_SUPPORT_GROUP_ASSOC_LOOKUP. Login_id = hd. SUBMITTER) < br / > AND (CTM_SUPPORT_GROUP_ASSOC_LOOKUP. DEFAULT_X = 0) < br / > AND < br / > (< br / > CTM_SUPPORT_GROUP_ASSOC_LOOKUP.) SUPPORT_GROUP_NAME In ('Service DESK', "Z-SERVICEDESK") < br / > AND < br / > TRUNC (hd. SUBMIT_DATE / 86400 + TO_DATE('12/31/1969 5:00:00 PM','MM/DD/YYYY HH:MI:SS AM')) BETWEEN to_date (October 28, 2008 ', 'dd-mm-yyyy') AND to_date (October 28, 2008 ', 'dd-mm-yyyy') < br / >) < br / > < / pre > < br / > < br / > {color: #000080}

all I get as a result of the first query is divided by the result of the second query. Is it possible to combine these two queries and come up with one that gives me the percentage/rate?

Thanks in advance! {color}

In a very simplistic way, they can be combined like this:

WITH t1 AS
    (SELECT COUNT( hd.ENTRY_ID ) c1
       FROM HPD_HELP_DESK_ASSIGNMENT_LOG
          , HPD_HELP_DESK hd
          , CTM_SUPPORT_GROUP ResolvedByGroup
          , CTM_SUPPORT_GROUP
          , CTM_SUPPORT_GROUP_ASSOC_LOOKUP
      WHERE hd.REPORTED_DATE >=(( SYSDATE - TO_DATE( '1-1-1970 00:00:00', 'MM-DD-YYYY HH24:Mi:SS' ) ) *( 24 * 60 * 60 ) ) -( 24 * 60 * 60 ) --Reported last 24 hrs.
        AND ( hd.ASSIGNED_GROUP = 'SERVICEDESK'
         OR hd.ASSIGNED_GROUP = 'Z-SERVICEDESK' )
        AND ( hd.RESOLVED_BY_GROUP = 'SERVICEDESK'
         OR hd.RESOLVED_BY_GROUP = 'Z-SERVICEDESK' )
        AND hd.resolved_by_group = hd.assigned_group
        AND hd.total_transfers = 0
        AND ( hd.LAST_RESOLVED_DATE - hd.REPORTED_DATE ) <( 60 * 60 * 1 ) --resolved within 1hours
        AND hd.SUBMITTER = hd.ASSIGNEE_LOGIN_ID
        AND hd.SERVICE_TYPE = 0
        AND ( HPD_HELP_DESK_ASSIGNMENT_LOG.INCIDENT_ENTRY_ID(+) = hd.ENTRY_ID )
        AND ( CTM_SUPPORT_GROUP_ASSOC_LOOKUP.LOGIN_ID = hd.SUBMITTER )
        AND ( CTM_SUPPORT_GROUP_ASSOC_LOOKUP.DEFAULT_X = 0 )
        AND ( CTM_SUPPORT_GROUP.SUPPORT_GROUP_ID(+) = hd.ASSIGNED_GROUP_ID )
        AND ( hd.RESOLVED_BY_GROUP = ResolvedByGroup.SUPPORT_GROUP_NAME(+) )
        AND ( CTM_SUPPORT_GROUP_ASSOC_LOOKUP.SUPPORT_GROUP_NAME IN( 'SERVICEDESK', 'Z-SERVICEDESK' )
        AND TRUNC( hd.REPORTED_DATE / 86400 + TO_DATE( '12/31/1969 5:00:00 PM', 'MM/DD/YYYY HH:MI:SS AM' ) )
            BETWEEN to_date( '28-10-2008', 'dd-mm-yyyy' ) AND to_date( '28-10-2008', 'dd-mm-yyyy' ) )
    )
  , t2 AS
    (SELECT COUNT( hd.ENTRY_ID ) c2
       FROM HPD_HELP_DESK hd
          , CTM_SUPPORT_GROUP_ASSOC_LOOKUP
      WHERE hd.REPORTED_DATE >=(( SYSDATE - TO_DATE( '1-1-1970 00:00:00', 'MM-DD-YYYY HH24:Mi:SS' ) ) *( 24 * 60 * 60 ) ) -( 24 * 60 * 60 ) --Reported last 24 hrs.
        AND hd.SERVICE_TYPE = 0
        AND ( CTM_SUPPORT_GROUP_ASSOC_LOOKUP.LOGIN_ID = hd.SUBMITTER )
        AND ( CTM_SUPPORT_GROUP_ASSOC_LOOKUP.DEFAULT_X = 0 )
        AND ( CTM_SUPPORT_GROUP_ASSOC_LOOKUP.SUPPORT_GROUP_NAME IN( 'SERVICEDESK', 'Z-SERVICEDESK' )
        AND TRUNC( hd.SUBMIT_DATE / 86400 + TO_DATE( '12/31/1969 5:00:00 PM', 'MM/DD/YYYY HH:MI:SS AM' ) )
            BETWEEN to_date( '28-10-2008', 'dd-mm-yyyy' ) AND to_date( '28-10-2008', 'dd-mm-yyyy' ) )
    )
 SELECT c1 / c2 FROM t1, t2;

Not knowing a lot about your tables and the selectivity of your questions, I am not sure how to move the two counts in the same query. You say that the first query is more selective than the second, so any effort to combine the two need to widen the scope of records returned by the first query must match that of the second query without losing selectivity of the County is in the first. This can be possible by relaxing the requirements in the where clause and moving them in a CASE statement in the COUNT function:

COUNT(CASE WHEN expression THEN hd.entry_id ELSE null END)

Published by: Sentinel on October 28, 2008 09:22

Tags: Database

Similar Questions

  • Sum of the combination of columns count

    Hi guru and expert.

    Help me please how to code this requirement in the PIF. (Please copy and paste in Excel the table below for the best table of data)

    Example of output:

    # GROUP SALES MARKETING TEAM BUSINESS HEAD RM/AO ADJUSTMENT TYPE ADJUSTMENT REASON NEWS REQUESTS THIS PERIOD
    Number OF QUERIES AMOUNT AMOUNT IN PhP
    1 CRM a CRB 1 BH3 RM5 recipes without acknowledgement of receipt 1 PHP400 400 Service
    2 CRM a CRB 1 BH4 RM6 operational reimbursements (failures / Interruption of Service) 1 PHP100 100
    3 CRM a CRB 1 BH4 RM6 operational reimbursements (failures / Interruption of Service) 1 USD100 5,000.00
    4 CRM a CRB 1 BH1 RM1 back continuous billing 1 400 USD 20 000.00
    5 CRM a CRB 1 BH1 RM1 back continuous billing PHP800 2 800
    6 CRM B CRB 1 BH3 RM1 continuous income 1 billing USD210 10,500.00
    7 CRM B CRB 1 BH5 RM8 recipes without acknowledgement of receipt 1 PHP500 500 Service
    8 CRM B CRB 1 BH5 RM8 recipes without receipt Service 2 USD750 37 500.00
    9B CRM incorporate BH7 RM7 effective operational disputed billing Date 1 USD20 1 000,00
    10 B CRM incorporate BH2 RM3 operational returned cheques 1 PHP200 200
    11 B CRM incorporate BH2 RM3 operational returned cheques 3 USD270 13,500.00
    PhP89, 500.00


    Expected results:

    # GROUP SALES MARKETING TEAM BUSINESS HEAD RM/AO ADJUSTMENT TYPE ADJUSTMENT REASON NEWS REQUESTS THIS PERIOD
    Number OF QUERIES AMOUNT AMOUNT IN PhP
    1 CRM a CRB 1 BH3 RM5 recipes without acknowledgement of receipt 1 PHP400 400 Service
    2 CRM a CRB 1 BH4 RM6 operational reimbursements (failures / Interruption of Service) 1 PHP100 100
    3 CRM a CRB 1 BH4 RM6 operational reimbursements (failures / Interruption of Service) 1 USD100 5,000.00
    4 CRM a CRB 1 BH1 RM1 back continuous billing 1 400 USD 20 000.00
    5 CRM a CRB 1 BH1 RM1 back continuous billing PHP800 2 800
    6 PhP26300
    6 CRM B CRB 1 BH3 RM1 continuous income 1 billing USD210 10,500.00
    7 CRM B CRB 1 BH5 RM8 recipes without acknowledgement of receipt 1 PHP500 500 Service
    8 CRM B CRB 1 BH5 RM8 recipes without receipt Service 2 USD750 37 500.00
    4 PhP48500
    9B CRM incorporate BH7 RM7 effective operational disputed billing Date 1 USD20 1 000,00
    10 B CRM incorporate BH2 RM3 operational returned cheques 1 PHP200 200
    11 B CRM incorporate BH2 RM3 operational returned cheques 3 USD270 13,500.00
    5 PhP14700

    Kind regards

    Jean Paul

    As a simple solution, you can group data based on group and team sales, then on other 4 columns.
    This way you can easily follow the end of the combination of group sales / team and print the number and total it.

  • Is it possible to prevent the right click context menu of the combination of Stop/Reload?

    Is it possible (subject: config tweak or something) to prevent the context menu of the combination of Stop/Reload?

    Screenshot of what I mean: http://picsend.net/images/873089StupidReloadSto.png

    Try to add this code in the file userChrome.css below default @namespace.

    Customization files (interface) userChrome.css and userContent.css (Web sites) are located in the chrome folder in the user profile folder.

    @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
    
    #context-stop,#context-reload[hidden="true"] { display: -moz-box!important; }
  • Re: How to disable the function and the combination of the space bar key?

    How can I change the combination Fn + space?
    If I hit him, it changes the resolution of the screen. terrible :(

    p.s. I asked this question ten minutes ago, and now he's disappeared from the forum Board. does not pass the prior restraint?

    In the past, that Toshiba used utility zoom and this utility has been installed as an application unique os it wasn't the problem to remove it from the system.
    This application is now part of the Toshiba system parameters. I've checked my Satellite with Win8 and I find didn t the way how to turn off this option.

    I hope that someone else knows how to do this. I would also like to turn it off.

  • The combinations of keys FN on my Satellite L Windows 7 stopped working

    The combinations of keys FN on my Satellite L650 - 1 Hz, Windows 7 Home stopped working. Can someone tell me how to make them work again? And ideally, why they stopped?

    Try to restart flash cards. Start > all programs > Toshiba > utilities > restart Flash Cards

    If this will not help, try reinstalling additional package from Toshiba.
    Remove the preinstalled version and install the latest version of http://www.toshiba.eu/innovation/download_drivers_bios.jsp

    Please post comments.

  • How to build the table with all the combinations of a source table?

    Hello

    I have a 2D array that contains the list of the power user-defined settings. The number of PSs (table rows) is not fixed. For example - 3 PSs:

    Stage of Min Max name

    PS1 3.0 3.6 0.3

    PS2 0.9 1.2 0.1

    PS3 1.7 1.9 0.1

    I need to build, from this list, a table of all the combinations as below:

    PS1 PS2 PS3

    3.0 0.9 1.7

    3.0 0.9 1.8

    3.0 0.9 1.9

    3.0 1.0 1.7

    3.0 1.0 1.8

    3.0 1.0 1.9

    3.0 1.1 1.7

    3.0 1.1 1.8

    3.0 1.1 1.9

    3.0 1.2-1.7

    3.0 1.2-1.8

    3.0 1.2-1.9

    3.3 0.9 1.7

    3.3 0.9 1.8

    3.3 0.9 1.9

    3.3 1.0 1.7

    3.3 1.0 1.8

    3.3 1.0 1.9

    3.3 1.1 1.7

    3.3 1.1 1.8

    3.3 1.1 1.9

    3.3 1.2 1.7

    3.3 1.2 1.8

    3.3 1.2 1.9

    3.6 0.9 1.7

    3.6 0.9 1.8

    3.6 0.9 1.9

    3.6 1.0 1.7

    3.6 1.0 1.8

    3.6 1.0 1.9

    3.6 1.1 1.7

    3.6 1.8 1.1

    3.6 1.1 1.9

    3.6 1.2 1.7

    3.6 1.2 1.8

    3.6 1.2 1.9

    How to build this table programmatically?

    (Note also that the number of rows in the source table is not fixed).

    Thanks in advance!

    Hi Berezka,

    using a magic of automatic indexing:

  • Changed the behavior of the combination SHIFT + click in Editor?

    In versions cc2015 of Photoshop, the checker behaves differently than older versions when I use 'shift-click' to connect the dots. In PS CS6, for example, when I take the SHIFT key, the clone tool in (or cure) continuously from point to point as I click. In the last two versions of Photoshop, this has changed: a click, then shift + click to a new location translates into a 'line', although it is not until the next point clicked, even by pressing the SHIFT key all the time. Instead, the point is considered as the beginning of a second 'line' of healing.

    I hope that makes sense - it's surprisingly complicated to describe such a simple thing. But the effect is really disconcerting - if I'm along a surface of healing, I can't have a continuous 'cure' along a curve, for example.

    Tools brush and Clone Stamp don't show it at all - they behave as expected, click connection points without interruption until the SHIFT key is released. I can't find any preference which may have changed, and I'm using a very simple toolset - without wild brushes or anything like that. Very frustrating!

    How can I get the old behavior back to the Healing Brush tool? What Miss me?

    Thank you

    John

    -running Mac OS X 10.10.5, Photoshop versions cc2015 and cc2015.5 show that (also another machine at work, OS 10.11, PS cc2015.5.1 shows the same behavior)

    I have been informed more in 'PhotoshopFamily' that it is a bug, they sent to engineering to investigate (& difficulty, hopefully!)

    «More tests, I found that this problem goes away * if * the source and the destination are on a layer "background" (e.g., on a flattened image).» But try to 'cure' / clone of a source layer to a layer of different destination (or even the same layer, if not a background layer) product failure in the behavior of the combination SHIFT + click. »

  • getting the error for queries

    Team dear community,

    I made two requests yesterday for which I am getting following error.

    Not found

    The item does not exist. It may have been deleted.

    Not sure why this happened.

    Here's the URL for queries

    1. https://community.oracle.com/message/12927951#12927951

    2 https://community.oracle.com/message/12928209#12928209

    rukbat wrote:

    Had you tried to post your questions about 24 hours earlier?

    You seem to be a new Member of these forums

    He was be a flood of spam that the moderators have faced this moment here.

    All new messages by new users of the forum are filtered through a queue of inspection and your posts have been neglected and buried among the flood of spam.   It is possible that positions have been purged while the spams have been served.

    Already mentioned that

  • Can I download the Stock Images I paid for to photo sites such as imgur of sharing and so on, so that I declare that copyright law and they are not downloadable etc.? Secondly, can I modify Stock photos, for example the combination two photos, change temp

    Can I download the Stock Images I paid for to photo sites such as imgur of sharing and so on, so that I declare that copyright law and they are not downloadable etc.? Secondly, can I modify Stock photos, for example the combination two photos, change templates?

    Hello

    Please see Stock Licensing & conditions FAQ: where can I find the terms and the license information for Adobe Stock?

    Hope that helps!

    Kind regards

    Sheena

  • Please help me with the Alternative of queries to replace the UNION ALL for two queries

    Hi all

    I have the query to retrieve assets employees salary count and in so far as below:

    Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of

    (select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1

    where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")

    UNION ALL

    Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the

    where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "

    Group of emp_no, ename;

    In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.

    But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.

    Advice me with request to read the table once to fetch the same data as the above query.

    Thanks in advance.


    Hello

    Thanks for the display of the data of the sample; It's very useful!

    I think OP wants something like this:

    WITH cutoff_dates AS

    (

    SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL

    SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014

    )

    SELECT e.emp_no, e.ename

    , NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010

    , NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014

    E employee

    JOIN cutoff_dates c ON e.effective_date<=>

    WHERE DOES NOT EXIST)

    SELECT 1

    Of employee_deletion ed

    WHERE ed.emp_no = e.emp_no

    AND ed.deletion_date<=>

    )

    E.emp_no GROUP, e.ename

    ORDER BY e.emp_no

    ;

    Output of your sample data:

    EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014

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

    1 Mickey 450 0

    2 Donald 750 0

  • Hello! Two weeks ago I paid $94 for the combination of files Adobe software, even today, I can't combine my unique Adobe files. The system asks me to pay again. Why don't the sysstem grant me access to this step? Why should users pay extra for that

    Important question

    Hello! Two weeks ago I paid $94 for the combination of files Adobe software, even today, I can't combine my unique Adobe files. The system asks me to pay again. Why don't the system gives me access to this step? Why should users pay extra for this tool?  This transaction is located on my credit card. Help, please. Sincere thanks. BP

    Hi pruitt-mckenzie-animated.

    I see that you have subscribed for the Adobe PDF pack.

    Please download latest Adobe Acrobat Reader DC Acrobat Reader DC Learn & support, Sign In using your adobe ID to use the services.

    KB doc. for help Document Cloud Help | Adobe PDF package using.

    Let me know if you are still having a problem.

    Kind regards

    Nicos

  • How can I stop my letters "S" and "T" of the combination? CS5.5

    Whenever I type in a letter 't', it is very well. But when a 't' following a ', combine the two letters at the top.

    How can I solve this?

    What the police? If they are the combination you must have a ligature option is enabled and that particular font has a ligature "ts".

  • When you use the harvesters, pages deleted in DOC files remain in the combined file

    Acrobat Standard XI. I use combine to edit and merge different files. When I add a DOC file and delete certain pages within this DOC file, these "deleted" pages remain in the combined output PDF file. What should I do?

    First of all remove the pages in Word, and then save the document.

  • How can I create a constraint on the combination of four columns...

    Dear Guru,

    I have a question... I created the table with columns like "CCode', 'Size1', 'Size2', 'Sch1', 'Sch2', 'Description', 'CCdate '.

    Here I wanted to create a unique constraint on the combination of four columns "CCode', 'Size1', 'Size2', 'Sch1', 'Sch2.

    My requirement is that I don't want to allow duplicate records in the table for the four columns only.

    for example: "CC123", 10, 25, S110, S250,.

    If the new record comes with the same data. Then, I do not want to insert this record.i want to get a constraint voilated error.

    How can I create a constraint on the combination of four columns...

    Pls help me on this issue...

    Kind regards

    Shitab...

    I suggested already here the syntax,

    ALTER table your_table

    Add constraint cons_name unique (col1, col2, col3, col4, col5);

    And don't call me 'Sir '.

    See you soon!

  • I have 9, 1 pages in PDF files that are accessible and the need to combine them into 1 PDF file.  I tried adding, adding and the combine process of PDF files. The file created does not take my changes. The file created is partially accessible, but I have

    I have 9, 1 pages in PDF files that are accessible and the need to combine them into 1 PDF file.  I tried adding, adding and the combine process of PDF files. The file created does not take my changes. The file created is partially accessible, but I have to re - the problems that I had fixed in the unique files. I need suggestions on what else can be done, if any. Using Acrobat pro XI.

    By habit, I tend to combine PDF files in the Page pane by right-clicking thumbnails then 'Insert of Pages'-> 'From File'. For me, this preserves the tags of these two documents, although the tags may have to be moved to the correct location (if I remember correctly the tags for inserted pages are put at the end of the tag structure, regardless of where the pages are inserted), if I put the tags in the document to insert into a container as a Section tag It makes the process easier. Travel set of tags in the right place is the only re-fixing that I remember having to do. What behavior you encounter?

    a 'C' student

Maybe you are looking for