Join with count() issue, please help!

Hello All,
I have this (probably really simple) issue that I cannot seem to resolve...I have 2 tables here (tbl_system_engineer and tbl_task_request)...(only relevant columns are listed below)
tbl_system_engineer
- id NUMBER
- full_name VARCHAR2
tbl_task_request
- tr_number NUMBER
- submitted_on_date DATE (date task was submitted)
- ass_comp_date DATE (date task is due)
- closed_date DATE (date task was officially closed)
- requestor NUMBER (the system engineer id, the person who created this task)
The query is supposed to summarize how many of the system engineers tasks are as followed:
- "past completion date" - how many tasks have tbl_task_request.closed_date > tbl_task_request.ass_comp_date OR SYSDATE > tbl_task_request.ass_comp_date for the engineer
- "Approaching Completion Date" - how many tasks have a tbl_task_request.ass_comp_date in this month but not "past completion date" for the engineer
- "On Schedule" - how many tasks have a tbl_task_request.ass_comp_date > the end of SYSDATE month and year
The result set rows are supposed to look like...
"System Engineer full name", past completion date count, approaching completion date count, on schedule count
Please help!

Hi,
Welcome to the forum!
That's an example of a Pivot , where you want to GROUP BY a combination of columns, and have some of the columns appear as different columns, not different rows.
The way to do that is to GROUP BY the expression(s) for which you want rows, and use CASE expressions for the others.
For example:
SELECT       e.full_name
,       COUNT ( CASE
               WHEN  r.closed_date     > r.xyz_comp_date
               OR    SYSDATE          > r.xyz_comp_date
               THEN  1
              END
            )     AS overdue
,       COUNT ( CASE
               WHEN  xyz.comp_date     <  ADD_MONTHS ( TRUNC(SYSDATE, 'MONTH')
                                                  , 1
               AND   r.closed_date     <= r.xyz_comp_date
               AND   SYSDATE          <= r.xyz_comp_date
               THEN  1
              END
            )     AS approaching
,       COUNT ( CASE
               WHEN  xyz.comp_date     >= ADD_MONTHS ( TRUNC(SYSDATE, 'MONTH')
                                                  , 1
               THEN  1
              END
            )     AS on_schedule
FROM       tbl_system_engineer     e
JOIN       tble_task_request     r     ON     r.requestor     = e.id
GROUP BY  e.full_name
;I don't have versions of your tables, so I can't actually test this. I suspect that some consideration for NULLs needs to be added to the CASE conditions.
if you post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) then people can test their ideas.
Sometimes, especially when the columns are mutually exclusive, it's simpler to calculate a value in a sub-query, telling with which column of output each row is associated. That computed value is then used in very simple CASE expressions in the main query,
Among the annoying features of this site is ithat ir replaces what it thinks are naughty words with s.  I suspect that happend in your post.  I assume all the columns with ** are the same, for which I substituted above.

Similar Messages

  • The "From" column in my Yahoo! e-mail account is blank. I trouble-shot it with them to no avail and they determined it was probably an issue with Firefox. Please help!

    The "From" column in my Yahoo! e-mail account is blank. I trouble-shot it with them to no avail and they determined it was probably an issue with Firefox. Please help it has been like this since Monday! Furthermore, it appears fine when I view my Yahoo! e-mail while using the Google Chrome web browser.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"

  • Battery with X and an "alleged" spill issue - Please help

    Hi Everyone, This is my first post here. I had an X on my battery (which seems to be a common issue) and I tried everything in the forums and it did not work. Later, I called apple support and they sent me a new battery. This did not solve the problem either. So, I sent the mac in for repairs and they told me that the logic board has corrosion due to liquid spill, and apple care would not cover it. The sad part is that I can vouch for the fact that there was no liquid on or around my laptop, since I use it for my research and no one can borrow it because of the restricted material (graduate school requirements). Please help, and let me know if there is any way out of this. Is there anything other than spillage that can cause this corrosion on the logic board?
    PS: The logic board had to be changed within two months of buying it, when the display stopped working, and so this is the third logic board within a year (pretty exciting life for a little mac book!).

    Thanks for the reply micheal, but is'nt it unfair that they think it is my fault, when my macbook went bad in a couple of months? I am sure it would be very difficult for me to prove that I am not at fault, but even they cannot prove their innocence (remember that the product has been opened by them and not me!). I feel like smashing the same laptop that I liked so much and buying something else, just to get over this. If any one has any experience with such issues, please let me know a sensible way of handling it. It is my word against theirs and I am losing sleep and possibly $1400 or so...any help is appreciated.

  • Mid 2010 15" MBP i5 A1286 POWER ISSUE-PLEASE HELP-

    The MBP works fine when mains connected but the only issue is every time I take the charger out it shuts down on me!!! So I have checked with a multitester & looks good the only thing i find hard to check for power is the battery itself as its hard to get a good connection, also I took to local Apple store & they checked with a new battery but said its still same issue so the guy disconnected nearly all the connecters off to check if they causing issue & he said now the battery is charging.
    So they still have the laptop to do further tests etc, but I’m not sure what could be the problem hear as maybe there is some component which is bad so the battery’s not charging or what else could be the issue please help & advice as I’m really confused as if it was something to do with the logic board then surely it would not even charge even after checking with the multitester or like Apple genius done by disconnecting other components...
    ANY HELP OR ADVICE WOULD BE HELPFULL,
    THANKS GUYS

    THANKS FOR THE HELP GUYS!!! BEEN AROUND 5 DAYS & NOT ONE PERON HAS HELPED...
    BUT YEAH THANKS AGAIN...
    WASTE OF TIME THIS IS...

  • Problem with streams with CC12.0, Please help

    Hi All,
    We have been facing some issue with the streams(ostringstream, stringstream etc.,) while using them with CC12.0 compiler.
    We are using the ostringstreams as:
    if (log.isBeingLogged(QbLogEntry::OUTPUT_DOC_DATA))
    // log the retrieved data:
    std::ostringstream oss;
    oss << result;
    log.logDebugInfo(..., oss.str());
    if (log.isBeingLogged(QbLogEntry::BILLING_DATA))
    std::ostringstream oss;
    oss << "Billing string: " << attrs.getBillInfo();
    log.logDebugInfo(..., oss.str());
    When the server is compiled using the CC12.0 compiler and we run the test case the server cores. The stack trace looks like:
    t@19 terminated by signal SEGV, bad address: 0xffffffffffffffff
    'where' revealed the following stack trace (abbreviated for clarity):
    [3] free
    [4] operator delete
    [5] std::ios_base::~ios_base
    [6] QbLogEntry::logUlongParm(this = 0xf7b4f4ac, parmName = 0x2fe378 "transactionAttributes", parmValue = 10U), line 221 in "QbLogEntry.C"
    This code works fine with Sun Studio 10.0 but we started facing issues with streams once we migrated to sun studio 12.0
    How can we resolve the issue please help.

    I see two problems with the command line.
    -R/l-n/app/colr/lib/infra/SunOS5.9/WS12.0
    Is this the directory where the compiler is installed? If so, remove this option. You should not use -I, -L, or -R options that point into the compiler installation area. The CC driver will add such options as needed.
    -D_RWSTD_SOLARIS_THREADS
    This macro definition is likely to cause program crashes. We do not support user modification of any of the library configuration macros (those starting with _RWSTD). The runtime library is built with a set of configuration macros. If you compile your program with a different set, the object code generated by your application will not be compatible with the runtime library.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • When i am trying to restore backup to my iphone, its coming up that back is not compatible with iphone. Please help me restore backup.

    Hi
    When i am trying to restore backup to my iphone, its coming up backup is not compatible with iphone. Please help me restore.
    Thanks
    Mandy

    From the article that the question was posted from:
    Error 1611
    This error typically occur when security software interferes with the restore and update process. Follow Troubleshooting security software issues to resolve this issue. In rare cases, this error may be a hardware issue. If the errors persist on another computer, the device may need service.
    Try reading the solutions you find in the future and follow them.

  • HT3939 i purchased iphone 5c from ebay india . after 35 days i updated software n from that day phone battry is not workin well , getting dry in 4 hrs . i m reaaly ****** with phone performace , please help or suggest

    i purchased iphone 5c from ebay india . after 35 days i updated software n from that day phone battry is not workin well , getting dry in 4 hrs . i m reaaly ****** with phone performace , please help or suggest

    Ebay is not an official reseller.  Return it if you can for a refund.
    Basic troubleshooting from the Users Guide is reset, restart, restore (first from backup then as new).  Try each of these in order until the issue is resolved.

  • Trackpad Issue - Please Help!

    Hi there,
    Hope you can help me out here.
    I've recently purchased a 15" i7 Macbook pro. The machine is but 3 weeks old &, of course, very well looked after.
    A few days ago, the built-in trackpad started behaving eratically. Cursor moving by itself, not responding to touch, clicking and opening things involuntarily. Not good at all. Many users seem to have had this exact same issue.
    These problems seemed to miraculously stop after a few re-boots and possibly a software update? I really couldn't tell you what resolved the problem.
    Unfortunately I now have a totally different problem.
    There is a thin, possibly 8 to 10mm horizontal strip across the centre of the trackpad that no longer responds to touch. If I move my finger from the botom of the trackpad upwards (or vice versa), the cursor will stop momentarily as it passes over the horizontal strip. The buttons are fine and the rest of the trackpad is fine. For the moment, I've increased the cursor acceleration so that I can at least navigate round the screen with a smaller area of the trackpad. USB magic mouse seems to work fine.
    If anyone else has experienced this &/or found a solution for this issue, please help me out here. I have rifled through endless threads about MBP trackpad issues with little success & do not live close to an apple store/genius bar.
    This is a 3 week old machine that cost me a small fortune. To be getting software/hardware issues so early on in it's lifespan is really rather worrying for the future.
    Appreciate your help here.
    J

    I'm not sure what caused this, but I extended my lunch break and drove the machine down to the Westfield apple store. I didn't have an appointment with the Genius Bar but I managed to persuade one of the staff to speak to a technician in the workshop. She came back into the store and told me that they had replacement trackpads and that , considering the machine was only 3 weeks old, the technicians kindly sandwiched the repair into their timetable at zero cost. 2 Hours later, I now have a perfectly functioning trackpad/machine.
    I can't thank them enough.
    My only gripe is that I couldn't speak to a technician to find out what the problem was, how they resolved it or what causes these issues for future reference. Understanding why these problems occur often helps to build your own framework of understanding. Most of the threads i've read about trackpad issues are largely unresolved with people only speculating the problem/solution.
    The initial issue I had with the trackpad's erratic behaviour seemed to be a well known problem that many are associating with a trackpad firmware update. Unless by pure coincidence I had an immediate & major hardware fault after it, which is unlikely, my personal guess is that the two issues were related.

  • I have apple id but in this week i see this error : you must verify your payment info befor you can make purchases. please help me. i have not credit card but i buying apps with gift card. please help me

    i have apple id but in this week i see this error : you must verify your payment info befor you can make purchases. please help me. i have not credit card but i buying apps with gift card. please help me

    Why do you keep making multiple posts with this issue? You have now posted it three times in the last hour and have two different people helping you in two different threads!
    https://discussions.apple.com/message/18606895
    https://discussions.apple.com/message/18606685
    This is bad internet manners.

  • Microphone of my iphone is not working when i call anyone nobody can listen but me, its working with headphone but its also working with videocam recording, please help me to solve this probelm.

    microphone of my iphone is not working when i call anyone nobody can listen me its working with headphone. but it is working with videocam recording, please help me to solve this probelm.

    Try this:
    1. Reset the iPhone by pressing and holding the sleep/wake and home buttons and releasing them, when the Apple logo appears on the display. Now test again.
    2. If the issue persists: Restore the iPhone without any of your own content, using this description from Apple: http://support.apple.com/kb/HT4137
    3. If the issue persists, Your iPhone need repair.

  • Transport Issue Please help

    Hello,
    I have got a major prolen during transport.
    I have GEMPLOYE1 Which is a time dependient master data. which has Attribute called 0COUNTRY_ID.
    I have a custome attribute Called Actual PSGroup/Grade GPAYSCGR which has a compounpunding attribute 0COUNTRY_ID
    Now when I am trying to transport PSGroup/Grade GPAYSCGR to QA that transport is failing , the log massage is
    Characteristic GEMPLOYE1: Attribute GPAYSCGR compounded to 0COUNTRY_ID has a diff. time-dpdncy
    If any one saw this issue, please help me to fix the same.
    Samit

    Hi Venu,
    We can't add authorisation objects on Individual servers.We need to add authorisations on BWD ie Dev system and transport to BWI QUA system.This is the Process we need to follow as per our rule set.
    So,As the problem mentioned above if i add some auth. objects on BWD DEV system and transport it to BWI QUA system,it is getting transported Successfully to BWI,but the auth.objects what i have added on BW DEV system is not found on BW QUA system.
    What could be the problem for that,Is that the problem with transports like TP error or is it related with some tables of auth.objects...................
    Could u please analyse the problem and tell me the solution for this..........
    Thanks Much
    Swapna.D

  • I want to downgrade my 2011 mac mini server to mac os x, i want to downgrade my 2011 mac mini server to mac os x i have the disks but the mini willl not reboot the apple changing to a circle with a line please help-

    i want to downgrade my 2011 mac mini server to mac os x i have the disks but the mini willl not reboot the apple changing to a circle with a line please help-

    bpruse,  I may be completely off-track for your issue, but I had a similar situation where I wanted to downgrade a Mac Pro from Server to plain OS X and it would not boot from the OS X install disk.
    I was attempting to use a full-install OS X.6.x disc with an earlier SL version than that which originally came installed on the Mac Pro.  After two or three hours of fiddling, I figured it out and used the discs that came with the system.
    However, I don't know how that would work in your case if this is the mini server-version.  I'm sure the disks would only have Server on them.  Worse-case scenario, find out which X.6.x the OEM disc is installing and get an OS X disc with a new installer.
    HTH.
    lnail

  • My ipod generation 5 will not come out of recovery mode. i was simply updating my software and this happened. it will not let me restore it comes up with and error. please help, thanks.

    my ipod generation 5 will not come out of recovery mode. i was simply updating my software and this happened. it will not let me restore it comes up with and error. please help, thanks.

    Hey erinoneill24,
    Thanks for using Apple Support Communities.
    Sounds like you can't update your device. You don't mention an error that it gives you. Take a look at both of these articles to troubleshoot.
    iPod displays "Use iTunes to restore" message
    http://support.apple.com/kb/ts1441?viewlocale=it_it
    If you can't update or restore your iOS device
    http://support.apple.com/kb/HT1808?viewlocale=de_DE_1
    If you started your device in recovery mode by mistake, restart it to exit recovery mode. Or you can just wait—after 15 minutes the device will exit recovery mode by itself.
    Have a nice day,
    Mario

  • IPhone 4s not being recognized and cannot be activated for service--what does this mean? I can't sync with iTunes. Please help

    iPhone not being recognized and cannot be activated for service--what does this mean? I can't sync with iTunes. Please help.
    When I connect iPhone to USB iTunes is giving me the above message. Please advise if you know the fix.
    Thanks,
    Lina1116

    did you find a fix?

  • My Ipod wont Sync with ITunes! Please Help!

    My Ipod wont Sync with ITunes! Please Help! I have the latest version of Itunes, but my ipod will not sync with my laptop. The diagnostic test has no answers and says everything is normal. When i try to sync, it says "an unknown error occurred (-39)". Any suggestions?

    check for any viruses

Maybe you are looking for