Prioritizing counts using date

last week I asked for some help with a query that acquired distinct counts from an aggregate table and removed any duplicates based on a priority ranking. Now I want to throw an additional conundrum into the puzzle.
What if two of the categories have "equal" ranking priority and if there are duplicates, decide priority by an additional factor (in this case the actual start date of the service).
Here is a snipit of the code John helped me with last week.
SELECT region_id, region_name, officegroupname, officegroupid,
SUM(basic_readjustment) basic_readjustment,
SUM(occupation_skills) occupation_skills,
SUM(on_the_job) on_the_job,
SUM(placement_assist) placement_assist,
SUM(other) other,
SUM(basic_readjustment + occupation_skills + on_the_job + placement_assist + other) total
FROM (SELECT region_id, region_name, officegroupname, officegroupid,
SUM(DECODE(service_id, 'C', 1, 0)) basic_readjustment,
SUM(DECODE(service_id, 'B', 1, 0)) occupation_skills,
SUM(DECODE(service_id, 'A', 1, 0)) on_the_job,
SUM(DECODE(service_id, 'D', 1, 0)) placement_assist,
SUM(DECODE(service_id, 'E', 1, 0)) other
FROM (SELECT program_enrollment_id, officegroupname, officegroupid, region_id, region_name,
MIN(DECODE(service_id, 369, 'A', 368, 'B', 144, 'C', 114, 'D', 'E')) service_id
As you can see, service_id '369' is prioritized higher than '368' What I want to do now is rank both of them equally and "IF" both exist, count only one based on which has the most recent 'actual_start_date'
Any ideas? Thanks in advance.... Mark

Mark:
I've got to stop posting partial code. It is too easy to foul things up, specially with a lot of nested selects.
Between my partial code, and your pasting, the predicates on wia_base_mv got moved way out of place. The corrected code (I hope) is below.
SELECT region_id, region_name, officegroupname, officegroupid,
       SUM(basic_readjustment) basic_readjustment,
       SUM(occupation_skills) occupation_skills,
       SUM(on_the_job) on_the_job,
       SUM(placement_assist) placement_assist,
       SUM(other) other,
       SUM(basic_readjustment + occupation_skills + on_the_job + placement_assist + other) total
FROM (SELECT region_id, region_name, officegroupname, officegroupid,
             SUM(DECODE(service_id, 'A', 1, 0)) on_the_job,
             SUM(DECODE(service_id, 'B', 1, 0)) occupation_skills,
             SUM(DECODE(service_id, 'C', 1, 0)) basic_readjustment,
             SUM(DECODE(service_id, 'D', 1, 0)) placement_assist,
             SUM(DECODE(service_id, 'E', 1, 0)) other
      FROM (SELECT program_enrollment_id, officegroupname, officegroupid,
                   region_id, region_name,
                   MIN(DECODE(service_id, 369, 'A', 368, 'B', 144, 'C', 114, 'D', 'E')) service_id
            FROM (SELECT program_enrollment_id, officegroupname, officegroupid,
                         region_id, region_name, service_id,
                         ROW_NUMBER () OVER (PARTITION BY program_enrollment_id,
                                                          officegroupname,
                                                          officegroupid, region_id,
                                                          region_name
                                             ORDER BY DECODE(service_id, 369, 'A', 368, 'A', 144, 'C', 114, 'D', 'E'),
                                                             actual_start_date DESC) rn
                  FROM wia_base_mv
                  WHERE region_id < 13 AND
                        program_value = 'VAL04_TAA' AND
                        actual_completion_date IS NULL)
            WHERE rn = 1
            GROUP BY program_enrollment_id, officegroupname, officegroupid,
                     region_id, region_name)
      GROUP BY program_enrollment_id, officegroupname,
               officegroupid, region_id, region_name
      UNION ALL
      SELECT r.region_id, r.region_name, og.officegroupname, og.officegroupid,
             0 basic_readjustment, 0 occupation_skills, 0 on_the_job,
             0 placement_assist, 0 other
      FROM officegroup og, regions r, office_data od
      WHERE r.region_id = od.region_id AND
            og.officeid = od.office_id)
GROUP BY region_id, region_name, officegroupname, officegroupid
ORDER BY region_id One thing I find really useful in trying to figure out code like this is to start with the innermost query (in this case, the select from wia_base_mv), then add the outer layers one by one until I get to the one with the error. This often helps clarify what is wrong. It also helps when trying to get a handle on what someone else's code is doing.
HTH
John

Similar Messages

  • How to use Count with Date Parameters

    Hello,
    I am having issues using the Count() function in conjunction with date parameters.
    This is a Siebel report and in my report I have 2 date parameters(From Date, To Date). In a nutshell I am basically trying to count Opportunities that has a start date within the given date period. However I don't see a reasonable way to put my date parameters within the Count() function. The reason being is that I need to have a huge chunk of code to convert the dates into a common format that can be compared, and it won't even fit within the code block in my rtf template. I am not even sure how to put multiple conditional statements inside a Count() function since all the examples I have seen are very simple.
    Anyone have a suggestion on how to use Count() with date parameters?
    Thanks.

    Any chance you can get the date formats in the correct format from siebel?
    I don't know Siebel - so I can't help you with that. If you get the correct format it is just
    <?count(row[(FromDate>=date) and  (date<=ToDate))?>
    Otherwise the approach would probably need to use string function to get year/monthd/day from the date
    and store it into a varialbe and compare later the same way
    <?variable@incontext:from; ....?>
    <?variable@incontext:to; ...?>
    <?count(row[($from>=date) and  (date<=$to))?>
    Potentially you can use the date functions such as xdofx:to_date to do the conversion
    [http://download.oracle.com/docs/cd/E12844_01/doc/bip.1013/e12187/T421739T481158.htm]
    But I am not sure if they are available in your siebel implementation.
    Hope that helps

  • Got a new Mac, my iTunes is whack, (No Play Count or Date Added)

    Hello, everybody. It's been a rough night.
    I currently own a G4 iMac and I just got a brand new Macbook. The Macbook is very nice, it's extremely speedy and I am sure I will grow to love it. We've got just one hurdle to get through together: the organization of my music in iTunes. Now, I've had the iMac for five years, and not long after I got it adding music to it became something of an importance, it was my music player. Over the past five years I've not only added thousands of songs, but meticulously and very specifically organized them into playlists based on the number of spins they have and when they were added. To a lot of people I know this sort of thing isn't a huge deal, but for me this organization became, and I kid you not, a huge, huge part of my life.
    So I get the new Macbook, fire it up and use Migration Assistant, (with the iMac in Target Disk Mode), to move my data over. When it's done I open the iTunes and am greeted with... nothing. Well, okay, all of my music is there, that's nice, (it's what iTunes is for, etc etc), but NONE of my play count or date added information remains. I weep inside.
    Being that this is my first new computer in five years, (a long time!), you might be able to tell that I was hesitant about upgrading. Before getting my Macbook I asked experts at the Apple Store if this method would work, and even received assurance from several people online that everything would be preserved. So, I did my homework, but my Macs and I both apparently failed the test. Here's where we are now:
    1. The iMac, (running Tiger), still has iTunes on it, with all the information, nothing seems to have changed on that end.
    2. The Macbook has a hard drive full of music with no playlist, play count or date added data.
    3. I do own an iPod where I backed up the music before the move. I know that the data information on playlists, play count and date added is on the iPod. I do not dare plug it in to the new machine for fear of the unknown.
    Which brings me here, is there some way, any way of rectifying this? Here is what I would like:
    1. For the Macbook iTunes to look EXACTLY like the iMac's does.
    2. For it to work with both my old iPods without question.
    This has been long, and I fear that some may pass it over as something too much of an banality to be needed help with. But like some collect shoes or hats, I collect music. It's a lovely collection and it's a large part of who I am. I could start all over, but that's sort of like saying the world could start over if it by chance happened to forget how to turn. It would take a lot of effort, and there would be some (more) tears, but I could move on. But I really, really don't want to. I just want things to be the way they were. I'd very much like to have this information present, and I thank you all for your time.

    ADDED:
    Now that I look at it, appears that nothing except for my applications transferred over. My old computer is listed in the Hard Drive, but I can't access any of the folders because I don't have that "level of privileges" or whatever, (odd, considering they're both my computers, do they need to be hooked up for this?). I don't really need for my old applications to be there, (Hello, iWork '06 Demo!), so can I just go and erase them, or am I better just starting all over again?

  • How to create a counter using Oracle SQL Developer?

    Is there any way to create a counter using Oracle SQL Developer to create the below scenario. Meaning it will recorded down the name of user and ID and time and the date they login.
    Library portal home statistics shows how many users (outside and within the campus) visit the library portal.
    Page Access statistics is recorded on an hourly basis. Users may select the statistics by
    yearly (statistics displayed by all months in the selected year)
    monthly (statistics displayed by all days in the selected month)
    daily (statistics displayed by all hours in the selected day)

    I'm giving here one basic post - hope this will solve your problem --
    SQL>
    SQL>
    SQL> create table audit_info
      2   (
      3     usr        varchar2(50),
      4     log_time   timestamp(6)
      5    );
    Table created.
    SQL>
    SQL>
    SQL>  create table err_log
      2     (
      3       log_cd      varchar2(20),
      4       log_desc    varchar2(500)
      5     );
    Table created.
    SQL>
    SQL>
    SQL>   create or replace procedure ins_err(errcd   in  varchar2,
      2                                        errnm   in  varchar2)
      3    is
      4      pragma autonomous_transaction;
      5    begin
      6      insert into err_log values(errcd,errnm);
      7      commit;
      8    end;
      9  /
    Procedure created.
    SQL>
    SQL>
    SQL>   create or replace procedure ins_aud(ud   in varchar2,
      2                                        unm  in varchar2)
      3    is
      4      pragma autonomous_transaction;
      5    begin
      6      insert into audit_info values(ud,unm);
      7      commit;
      8    exception
      9      when others then
    10        ins_err(sqlcode,sqlerrm);
    11    end;
    12  /
    Procedure created.
    SQL>
    SQL>
    SQL>
    SQL> create or replace trigger log_odsuser1
      2   after logon on odsuser1.schema
      3   begin
      4     ins_aud('ODSUSER1',sysdate);
      5   exception
      6     when others then
      7       ins_err(sqlcode,sqlerrm);
      8   end;
      9  /
    Trigger created.
    SQL>
    SQL*Plus: Release 9.2.0.1.0 - Production on Tue Jun 12 12:21:09 2007
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL>
    SQL>
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL>
    SQL> select * from audit_info;
    USR
    LOG_TIME
    ODSUSER1
    12-JUN-07 12.00.00.00000000 AMHope this will solve your purpose.
    Regards.
    Satyaki De.

  • Distinct count on date/time field...

    Hi,
    I am trying to a distinct count on this formula that takes a date/time field and converts it to a date in order to get a distinct count of dates.  However, it's not working... say, if I have two dates are the same (the times may be different), it's counted twice.  Any suggestions?  I tried to convert this to a string thinking the evaluation may change, but no dice.  Thanks!!
    if not isnull({AVAILABILITY.PAT_ENC_CSN_ID}) then
        cstr(cdate({AVAILABILITY.SLOT_BEGIN_TIME}))
    else

    You can use the following formula...
    DateAdd("d", DateDiff("d", #1/1/1900#, {TableName.YourDateTimeField}), #1/1/1900#)
    This will set each date value to 12:00 am of it's respective day...
    So 8/16/2010   3:01:20PM would become 8/16/2010  12:00:00AM
    Now you can group on this formula field and then simply do a count on the date at the appropriate group level.
    HTH,
    Jason

  • File Count using SPFile Object

    Hi,
    I am trying to get the file count using through SPFile within the selected dates of date time controls as below.
    But not able to get the count of the files in the folder as there is not count property in the SPFile object.
    Please share your ideas/thoughts on the same.
                                    foreach (SPFile file in oFolder.Files)
                                        if ((file.TimeCreated > dtFromDate.SelectedDate) &&( file.TimeCreated<dtToDate.SelectedDate))
                                            int filecount;                              
    Regards,Sudheer
    Thanks & Regards, Sudheer

    Hi ,
    as you have int filecount, increase the count whenever it satisfies the if condition as mentioned
    above.
    int filecount=0;         
    foreach (SPFile file in oFolder.Files)
        if ((file.TimeCreated > dtFromDate.SelectedDate) &&( file.TimeCreated<dtToDate.SelectedDate))
                               filecount++;           
    Thanks,
    Vivek
    Please vote or mark your question answered, if my reply helps you

  • How to determine what's using data store temp space?

    How can one determine what's using data store temp space? We are interested to know what structures are occupying space in temp space and if possible what pid/process connected to TimesTen created them.
    Also, is there a procedure that will work if temp space is full?
    Recently one of our data stores ran of space. We we're unable to run commands like "monitor", "select * from monitor", "select count(*) from my_application_table", etc. These commands failed because they required temp space to run and temp space was full. We killed the application processes, this in turned freed up temp space, then we were able to run these queries.
    Ideally, we'd like to have a procedure to figure out what's using temp space when temp space is full.
    The other thing we could do is periodically monitor temp space prior to it filling to determine what's using temp space.

    That was my original thought, but once you click the slider track or thumb, and then enter a value in the text control, the clickTarget on the change event envoked by the change to the bound data (after entering a value in the text control) will be whatever slider element had last been clicked. If you've never clicked the slider, clickTarget=null. But once you've clicked the slider the clickTarget always has a value of "thumb" or "track", regardless of what triggered the change event.

  • Perform Full Cycle Count - No Data Found

    I am trying to initialize a full cycle count for all items in a subinventory. I have a recent ABC compile set and a new cycle count setup. A, B, C and D classes are all set to count 1x per year. I have verified that all items from the compile are no in the cycle count. I submitted a "Cycle Count Scheduler" request and ensured that it completed. I then set all the parameters in the "Perform Full Cycle Count" request and set to save to file. After it completes and I view the output, the file says "No data found". My only recourse is to dump all items from Material workbench and use Data Load to enter them in ( a bit tedious for 900+ items). Is there anything I need to be doing different?

    You mention that you have done the ABC setups.
    But in Cycle count setups, have you defined a cycle count schedule?
    And more importantly, in cycle count classes, have you entered the frequency at which each class should be counted?
    Last but not the least, what is the last count date (on the serial and schedule tab)?
    If it is today, you will have to wait till tomorrow.
    Hope this helps,
    Sandeep Gandhi

  • Query on 0TCT_MC01 to get the last used date of a query

    Dear All,
    I tried to create a query on 0TCT_MC01 to get the last used date of a query.
    Since we do not have readily available key figure for Last used date, could any one help me out to achieve this result?
    I am interested to find the old queries which are not being used anymore.
    Thanks in advance.

    You can get the info from the below tables
    if you are working with BW 3.5 you can look in table RSDDSTAT in BI 7.0 it is RSDDSTAT_OLAP.
    Make a selction on the infocube and the OLAP Statistic Object which is the query ID and execute. Then you should see how often the query was executed, by whom and which date/time.
    in field Statistics Object Name Query ID you type in the tech name of the query
    from the Counter for statistics event calls -- will give the count... no of times the query used least the count lesser the query is used.
    Regards
    KP
    Edited by: Konduru Prashanth. on Dec 22, 2011 2:44 PM

  • Why is my texting using data? When I have data turned off I can't send/receive. Texting is "unlimited" but it's using up all my data- help!

    Why is my texting using data? When I have data turned off I can't send/receive. Texting is "unlimited" but it's using up all my data- help!

    Texting longer text messages or any media (pictures/video/sound etc) being sent requires data to be active. However, it does not count against your data caps.
    Since you have an iPhone, you must also be aware of the difference between iMessage and SMS Text messages. The iPhone, by default, will send an iMessage when sending another text message to anyone else with an iPhone, iTouch, or iPad. This does use your data if you are not connected to wifi. In Settings, you can turn iMessage off, and then all of your texts will go through Verizon.
    Also understand- iMessage will use wifi when connected to wifi, but would need cellular data connection to work when not connected to wifi. Regular SMS text messages that are long or any media will always use the cellular data and not wifi, so will not send if cellular data is turned off, even if on wifi. However, this does not count against your cap.

  • MiFi: Does data transfer within the home network count as data usage

    I want to use a MiFi with a wireless surveillance system, which can record 100s of GBs of video per month. If I send video to a PC all on the same network, does that count as data usage?

    Traffic sent over the local network will not be counted against your MiFi/data plan.  VZW charges for all traffic that is sent over thier wireless infrastructure/towers.  If this your question is then that is the answer.
    With that being said:
    You can setup your cameras and disconnect the MiFi from the VZW network.  There is a Disconnect button on the main page of the router admin page that allows you to do it.  This would enable you to maintain the local network and confirm that the security system will work offline.  After you confirm your camera to computer network is working you can reconnect it to VZW and see if you can access the computer / camera over the web. 
    As a local router the MiFi will perform just fine with your cameras and computers.  There are certainly better routers you can purchase for that function but thats another subject.  Its when you try to make your devices available over the internet where most people have problems.  Since the MiFi is a 4G capabile device it is tied into the new SIM card and NAT network.  In most cases public IP addresses are not assigned or accessible on the MiFi.  This makes it very difficult to get through to your devices from a remote location (as I assume you want to do).  Most users on this forum have not found a way around it other than reverting back to an older model like the MiFi 2200.

  • How to Modify Search for Leads using Date types in the Assgmnt Block Date

    Hello Experts,
    I have a requirement to modify the search for Leads using Dates in the Assignment Block Dates and using the Posting Date of the transaction.
    Any ideas?
    Thank you in advance,
    Justin

    If you look at the grants, you'll see that there are over 170 objects from the FLOWS_030000 granted to PUBLIC:
    SQL> select count(*) from dba_tab_privs where owner= 'FLOWS_030000' and grantee = 'PUBLIC';
    173
    If we were go grant these privileges to a role, called APEX_APP_RU, and grant this role to APEX_PUBLIC_USER and any schemas an application is linked to (Workspace to Schema), would that be a workable solution?
    The only problem I see right off hand that this might not work is that PUBLIC has synonyms created for the FLOWS_030000 objects. If we revoke the underlying privileges, because of the synonyms, this might not work.
    SQL> select COUNT(*) from dba_synonyms where table_owner = 'FLOWS_030000' and owner = 'PUBLIC';
    176
    Does anyone else have any ideas?

  • IMPORT_COUNTREQUEST API for Physical Count form data load?

    Dear All,
    Please clarify whether I can use the IMPORT_COUNTREQUEST API for physical count form data load...?
    or which other API does the job other than dataload through dataloader..
    Please update...
    many thanks in advance....

    Hi,
    We believe instead of using IMPORT_COUNTREQUEST API you can use a Dataload script to key in data in Physical Inventory form.
    Basically you need to populate 4 fields in this form, i.e Physical Inventory, Date, Description & Snapshot Complete (checkbox).
    Go ahead and write a Dataload script for the same.
    Regards,
    S.P DASH

  • Does FaceTime use data or cellular?

    Wanted to know if using FaceTime on a device does it count against the data share plan or uses unlimited minutes?  If it uses data how do we know how much data is used per minute?  I am using Verizon's broadband fusion and want to manage my data appropriately but need to know how to figure FaceTime use age.

    gina7239 wrote:
    You can use wifi or your data plan on your cell phone 3g or 4g. I don't know what broadband fusion is.
    I'm sure he's talking about HomeFusion

  • HTC DNA uses data when "Mobile Data" is set to off.

    I usually keep my phone sitting on my desk by my computer and when I get a text the speakers make that weird static noise.  More and more though I have been hearing this noise when there was no text incoming.  So I picked up my phone when it did it this one of the times and I noticed that 4G LTE was being used even though I have my "mobile data" option set to off (screenshot is attached).  So I went to the app Onavo Count and it told me it wasn't a lot of data, but there was in fact data being used by "Android OS + Others."  Does anyone know why this is happening because now that I was forced to get rid of my unlimited data plan I really don't want my phone to have the ability to use data without me even touching it.

    If they are actually recordings, there is no requirement for a data connection, but it honestly sounds like they are not recordings.
    As for the other issue... how are you pairing the iPhone, is it via Bluetooth or are you simply connecting to the Wi-Fi hotpsot?

Maybe you are looking for

  • Officejet Pro 8610 - Can't connect to wireless network (and has similar issue with previous printer)

    When I returned from a trip, I was unable to connect to my trusty HP All-in-one 7510 that I had on my network for three years.  I tried troubleshooting it, reinstalling the software on numerous computers, and fixing the printer, but alas the printer

  • Help with EJB Arch: Synchronous front-end -- Asynchronous back-end

    Hi folks, We are developing an application with the following characteristics: - users can invoke requests on our appl and they will expect a quick response - to obtain the information requested by the user, our application talks with Tibco using RV.

  • External USB Drive very slow to Mount

    Hi, I have an iBook G4 and I recently bought an 80GB external USB 2.0 drive. The problem I am having is that it takes a long time for the drive to mount. After I plug it into the USB port it takes 2 - 5 minutes for it to actually show up on my deskto

  • Alternative to Apple 24"

    Hello all, I am planning to order a new MacPro (2.66GHz Quad-Core Intel Xeon, 6GB Ram, 1TB HD, ATI Radeon HD 4870 512MB) and intend to use my old 20" Cinema Display with its iSight. Ideally I would like to get a HD resolution 24" display too (for fam

  • Counter in the condition procedure

    Hello Gurus,        why to use counter in the condition procedure ?  I think step is enough . Many thanks, Frank