Can you please help me write below query in efficient way

Hello-
I have wrote one query and its very slow to get the data because i am counting the code at every column from the table in from clause.
SELECT SUM(diag_total) diag_total,
SUM(diag_complete) diag_complete,
SUM(diag_remaining) diag_remaining,
SUM(diag_declined) diag_declined
FROM (SELECT hpc.dmpc_hicn,(SELECT COUNT(DISTINCT d.msd_icd9_ref)
FROM d4c_map_suspects_to_diagnosis d
WHERE trim(d.msd_sd_hicn) = trim(hpc.dmpc_hicn)) diag_total,
(SELECT COUNT(DISTINCT dd.dspd_icd9)
FROM d4c_suspect_provider_diagnosis dd
WHERE dd.dspd_ds_id_ref = 1000
AND trim(dd.dspd_hicn) = trim(hpc.dmpc_hicn)
AND trim(dd.dspd_npi) = trim(hpc.dpmc_provider_no)) diag_complete,
-- AND hpc.dmpc_ss_id_ref = 1020) diag_complete,
(SELECT COUNT(DISTINCT dd.dspd_icd9)
FROM d4c_suspect_provider_diagnosis dd
WHERE dd.dspd_ds_id_ref = 1010
AND trim(dd.dspd_hicn) = trim(hpc.dmpc_hicn)
AND trim(dd.dspd_npi) = trim(hpc.dpmc_provider_no)) diag_remaining,
-- AND hpc.dmpc_ss_id_ref = 1020) diag_remaining,
(SELECT COUNT(DISTINCT dd.dspd_icd9)
FROM d4c_suspect_provider_diagnosis dd
WHERE dd.dspd_ds_id_ref = 1020
AND trim(dd.dspd_hicn) = trim(hpc.dmpc_hicn)
AND trim(dd.dspd_npi) = trim(hpc.dpmc_provider_no)) diag_declined
--AND hpc.dmpc_ss_id_ref = 1020) diag_declined
FROM d4c_provider_assignment pc, d4c_hicn_provider_claims hpc
WHERE pc.pa_assignedto = &imrrid
AND trim(pc.pa_providerid) = trim(hpc.dpmc_provider_no));
Can you please help me in this?
Thanks in advance.
Kind regards,
Nik

May be this?
You dont even need sum as we are doing count for the whole data at a time. Please check the results and let us know if there is any issue.
SELECT COUNT (DISTINCT d.msd_icd9_ref) diag_total
      ,COUNT (DISTINCT CASE WHEN dd.dspd_ds_id_ref = 1000 THEN dd.dspd_icd9 END) diag_complete
      ,COUNT (DISTINCT CASE WHEN dd.dspd_ds_id_ref = 1010 THEN dd.dspd_icd9 END) diag_remaining
      ,COUNT (DISTINCT CASE WHEN dd.dspd_ds_id_ref = 1020 THEN dd.dspd_icd9 END) diag_declined
  FROM d4c_provider_assignment pc
      ,d4c_hicn_provider_claims hpc
      ,d4c_suspect_provider_diagnosis dd
      ,d4c_map_suspects_to_diagnosis d
WHERE     pc.pa_assignedto = &imrrid
       AND TRIM (pc.pa_providerid) = TRIM (hpc.dpmc_provider_no)
       AND TRIM (dd.dspd_hicn(+)) = TRIM (hpc.dmpc_hicn)
       AND TRIM (dd.dspd_npi(+)) = TRIM (hpc.dpmc_provider_no)
       AND TRIM (d.msd_sd_hicn(+)) = TRIM (hpc.dmpc_hicn);

Similar Messages

  • Can you please help me in creating a stored procedure which can create a tablesapce in a specified location ?

    Hello ...
    Can you please help me in writing a procedure which can create tablespace. like i have a requirement that
    through sql query i need to get the location of where the data file of the newly created tablespace need to be stored.
    I need to store the location of the datafiles in a variable and i need to use that variable for specifying the location of the data file in newly created data file.
    please help me writing this procedure.....
    Regards vinay raj.
    Thanks in advance..

    select distinct substr(file_name,1,instr(file_name,'/',-1)) from dba_data_files;
    Run this in a few of your databases and see how often you ONLY get one row returned.
    Normally there is no "default" file system for data files (read about the DB_CREATE_FILE_DEST parameter and Oracle Managed Files for the exception to that).
    You could pick the same file system as an existing tablespace, but even then there is no guarantee that the file system has sufficient space for the new tablespace - you have to check that OUTSIDE the database.
    Given the query at the top it is pretty simple to create a SQL script that generates a SQL script.  This can be run in any database via sqlplus, and then the generated script can be edited as needed and run immediately, under human control, avoiding surprises.
    set echo off
    set feedback off
    set heading off
    set lines 100
    spool myts.sql
    select distinct 'create tablespace MYTS DATAFILE '''||substr(file_name,1,instr(file_name,'/',-1))||'myts01.dbf'' size 40M ONLINE;' stmt
    from dba_data_files;
    spool off
    For example, if you find there are multiple filesystems to choose from, run this then delete the filesystems you don't want from the generated script.  If you find there is only one file system but it is too full, work with your SA or storage to to add space or allocate a new file system, then modify the generated script accordingly.
    This example assumes a traditional file system, on a UNIX-style OS, not using Oracle-Managed files.  ASM or RAW will have a different format for the data file location, of course.

  • Can you please help me how resolved this issue.

    Hi Experts
    I am trying to connect LDAP by R/3 system. R/3 system connected to LDAP but when I am trying to find and pull the fileds in the "Find in the Directolry" option I am getting below error.
    LDAPRC 010 another server is referenced.
    Can you please help me how resolved this issue.
    With Regards,
    Trinadh Bokka

    You may be able to solve by using
    Note 1151329 - Depth of LDAP search is only one level below the base entry
    Markus

  • Hi i am using  personal hot spot before updating 6.1.3.now iam using ios 6.1.3 version the personal hot spot is not working..can you please help me on this?how to use that,its in a default mode?

    Hi previously i use personal hotspot,after updating my 6.1.3 ios in india iam not able to use that.It is in a default mode.
    Can you please help me how to use personal hotspot.
    Thanks,
    Goutham.

    Im really good at programming but really suck at algorithms
    >If your are 'really good' at programming, you will be able to solve this problem. Because, it has nothing to do with algorithm.
    >>can someone please please write in a algorithm form for me , i need it by friday i would greatly be thankful for u
    >Wrong person, in the wrong place.

  • I have a scenario. Import IDOC into PI and PI transform IDOC to Excel. Using mail adapter attach that Excel using pi and send to customer. Can you please help me on the same?

    HI Experts,
    I have a scenario. Import IDOC into PI and PI transform IDOC to Excel. Using mail adapter attach that Excel using pi and send to vendor. Can you please help me on the same?
    Thanks
    SaiSreevastav

    Hi Sai,
    you can use XSLT or java mapping or adapter module to convert IDOC xml to XLS. Please refer the below blog
    Convert incoming XML to Excel or Excel XML – Part 1 - XSLT Way
    Convert incoming XML to Excel Sheet Part 2 – Adapter Module way
    Convert incoming XML to Excel Sheet
    then after converting to Excel, you can use the payloadswap bean in mail adapter
    XI: Sender mail adapter - PayloadSwapBean - Step by step
    regards,
    Harish

  • Hi i am working with indesign on a book in hebrew. and the page numbering that i apply. showing from left to right insted of right to left. can you please help?  thank you. iris

    hi
    i am working with indesign on a book in hebrew. and the page numbering that i apply. showing from left to right insted of right to left.
    can you please help?
    thank you. iris

    Hi Shawninglewood,
    Welcome to the Support Communities!
    The article below may be able to help you with this.
    How to delete content you've downloaded from the iTunes Store, App Store, iBooks Store, or Mac App Store
    http://support.apple.com/kb/HT5772
    Cheers,
    - Judy

  • Could you please help me make this query less complicated

    could you please help me make this query less complicated
    select t1.R_OBJECT_ID
    from dm_relation_sp a, ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID
    union all
    select t3.R_OBJECT_ID
    from ddt_resolution_sp t3
    where t3.R_OBJECT_ID in (select t2.child_id
    from dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    union all
    select t4.R_OBJECT_ID
    from ddt_resolution_sp t4
    where t4.R_OBJECT_ID in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    union all
    select t5.R_OBJECT_ID
    from ddt_resolution_sp t5
    where t5.R_OBJECT_ID in
    (select t4.child_id
    from dm_relation_sp t4
    where t4.parent_id in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    and t4.relation_name = 'RESOLUTION_RELATION')
    Edited by: user13025450 on 29.04.2010 16:23

    Hi,
    Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
    Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
    Describe what you're doing. Think about it: how do we know that
    SELECT  NULL
    FROM    dual;doesn't do what you want?
    Post CREATE TABLE and INSERT statements for a little sample data.
    Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
    Describe, as well as you can, how the present query is doing it.
    Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
    When posting formatted text (code or results) type these 6 characters
    \(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
    Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
    I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • HT4528 My IPhone Bugged out/It is currently in the reset mode. I need to exchange all of my contacts from my Yahoo acct. to my new IPHONE. Can you please help me?

    Hello ,
    I purchased my IPHONE about 2 months ago. I am visiting family in DE & this tuesday it starting to go off & on by itself. Then the icons looked like they were floating . Then I could not call or text . The SIRI device would not work. Then it would shut down then the apple icon would reappear. I took it to a verizon dealer in Rehoboth DE & they said it BUGGED OUT/It is in a RESTORE MODE. It will not turn on. We could not transfer anny of my pics or contacts. I never even had a chance to back up the memory on ITUNES.
    The tech @ Verizon said to contact APPLE to trouble shoot and try and transfer the contacts from my yahoo acct.
    Can you please help?
    Gina

    set up your yahoo account in mail, contacts, calendars as an Exchange Account and you should be able to get your contacts from Yahoo from there.

  • My ipod touch is stuck on the 4.2.1 software, its a 3rd gen as well i was just wondering why i can not get the lastest update can you please help me with this issue

    i have been having an issue with updating my ipod touch for some time now and i can not seem to get it to update to the lastest update. it is stuck on 4.2.1 software and i can not update it to 4.3 or any other ios software update. can you please help me to solve this issue.

    It sounds like you actually have a 2G iPod Touch which can only go as high as iOS 4.2.1.  If it's an 8 GB iPod Touch it's definitely a 2G iPod Touch as there was never such a thing as a 3G 8 GB iPod Touch. See this article to help verify what generation iPod Touch you have.
    Identifying iPod models
    B-rock

  • I wanted to update my itunes and it didn't update and now it wont open so i had to uninstall it and it wont install now at all can you please help?

    Hi
    I turned on my laptop this evening to import a new cd but it asked me if i wanted to download the new version of itunes so i went ahead to update it but it failed to update then it failed to open at all, and and runtime error keeps popping up but when i uninstalled it to reinstall it it wont install now and i cant use my ipod or ipad with my laptop without itunes and i never had this problem at all. can you please help?

    Hey maryncomiskey,
    Thanks for the question. I understand you are experiencing issues with the latest iTunes update. The following resource may help to resolve your issue:
    Issues installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/HT1926
    Additional Information:
    How to restart the Apple Mobile Device Service (AMDS) on Windows
    http://support.apple.com/kb/TS1567
    Thanks,
    Matt M.

  • I entered new fields in a form that was created last year to update it.  However, now when I view the responses, they are listed as Column 1, Column 5, etc.  It doesn't show a label for the actual field when I view the responses.  Can you please help?

    I entered new fields in a form that was created last year to update it.  However, now when I view the responses, the headings are listed as Column 1, Column 5, etc. rather than the name of the heading.  Can you please help?

    Hi Mike,
    CRSE is an OEM Product and for use with a custom application they have written. Unfortunately we don't their reports or how they are connecting, it would appear they were originally built off a SQL and then set to a Dataset in the app or they could be adding the data source at runtime. Lots of variations and without access to the source code to see what they are doing not much we can help you with.
    You need to contact the OEM Partner for help in resolving this and find out what you can and need to do to update your SP and work with their canned reports,
    Thank you
    Don

  • I have got 2 iPad Air one of it is not logging me in because I have forgotten the pass code and have logged out from iCloud by accident. Can you please help me to use my iPad.

    HI
    I have 2 IPads, I am unable to use one of it because I have forgotten my pass code and also logged out from iCloud accidentially. Can you please help me to solve this problem.
    Cheers
    Raveena

    Follow the instructions on this page : Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support

  • I am trying to use imovie and i have never had this problem before. All of my videos are completly grey and when you try and play them all i get is a black screen but i still hear audio.  Can you please help and tell me what i need to do. Thank you

    I am trying to use imovie and i have never had this problem before. All of my videos are completly grey and when you try and play them all i get is a black screen but i still hear audio.  Can you please help and tell me what i need to do. Thank you

    Make sure all of the videos used in the project that is having that problem are from the same event. If they are from multiple events, move them all into one event.

  • HT1688 Can you please help me. I purchased the new Apple I 4s phone from AT&T. I bought it out right. NO CONTRACT!! I paid almost $1000.00 for it. I then, had it enrolled it in my company's  ATT service plan. They paid the bill for my service. Since, I ha

    Can you please help me. I purchased the new Apple I 4s phone from AT&T. I bought it out right. NO CONTRACT!! I paid almost $1000.00 for it. I then, had it enrolled it in my company's  ATT service plan. They paid the bill for my service. Since, I have left the company. I have retained, and assumed financial responsibility for the phone, and the phone number with AT&T. The same day I assumed ifinancial responsibility, I had the phone number ported to a new service provider. ( Straight Talk ) After doing so, my phone worked fine. (as far as cellular service) NO DATA Service !!!! I have been on the phone with AT&T, Straight Talk, and Apple, FOR HOURS over TWO days!!! Trying  to get this problem resolved. All I need to do, is change my APN settings (access point name ) settings. Its  my phone!!! Why does any body have this APN menu locked from me??? I've been on the phone for two days between, AT&T, Straight Talk, and Apple products technical support teams. Everybody points the finger at the next guy!! What can I do to get the phone, that I paid for, work  for more than just a phone, and a paper weigh?
    PLEASE HELP ME!!!!!
    Jason
    Sent from my iPhone
    <Email Edited by Host>

    Wow... you seriously over paid for an iPhone.
    That probably explains why you have/had no clue you were purchasing a locked device and think it's an Apple problem to get it unlocked.

  • Can you please help me by saying me how can i join two different picture to make it as one picture.??

    Hi Sir/ Madam,
       My name is Rishav and I am facing some problem with my Photoshop CC. Actually I have a question. If you guys could help me out i will be very obliged. The quest in "Can you please help me by saying me how can i join two different picture to make it as one picture.??"

    Maybe you should post over at
    Photoshop for Beginners
    or start with the "Get Started" section of the Help:
    Photoshop Help | Photoshop Help
    And your question
    Can you please help me by saying me how can i join two different picture to make it as one picture.??
    does not seem particularly specific – do you want to simply combine two images as they are, do you want to clip elements from the one and insert them into the other, …?
    Could you post (lores of) the images and explain what you intend to achieve?

Maybe you are looking for

  • Between Dates SQL

    Hi, Can anyone help, I need to generate a pivot table using between two dates and a department. I am trying to acheive the following output: JAN-04 FEB-05 MAR-04 APR-04 MAY-04 JUN-04 JUL-04 AUG-04 SEP-04 OCT-04 etc DEPT 1 1 1 1 1 CF IF 1 1 1 1 1 The

  • Having trouble with my internet speed on Mac Pro tower.

    Hello all. I just had an AirPort card installed into my Mac Pro Tower (2.66 GHZ Quad-Core Intel Xeon, with 3 GB 1066 MHz DDR3 internal memory, Running OSX 10.6.4), and the internet is running, but at a snail's pace compared to my Mac Book Pro (2.66 G

  • Hi ,, question about abot_query .. plz

    hi ,, i made a form that contain 7 canvases,, i navigate from one canvas to the second one by push button "with 'when button pressed" trigger ,that load the second canvas in the "enter-query" mode,,, in this second canvas i make push button to cancel

  • Newbie problem....where do I find info on how to publish an app ?

    I have been hunting through the BB site trying to find a link, any link, that will take me to some instructions on how to do this.  I was warned it is much more time-consuming than publishing an Android app, but this is a bit much.

  • Internet via ethernet cable not recognised: just wireless

    Hi - I have an ethernet cable that supplies my internet, but Windows Vista (Home Premium) will only let me access a Wireless connection (of which I don't have one!). Can anybody help? Thanks!