How to use the case and decode to extract data

Hello gurus of PL/SQL,.

I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version

I have a table in the following form-
drop table TT2;
create table TT2(College, Class,gender,status,fees) as select
'IITB','MBA','M','P',255600 from dual union all select
'IITK','MTech','M','P',300000 from dual union all select
'IITD','MBA','F','P',450000 from dual union all select
'IITKH','MBA','F','P',350000 from dual union all select
'IITC','MTech','F','P',420000 from dual union all select
'IITB','MTech','M','P',185000 from dual union all select
'IITC','MTech','M','P',235000 from dual union all select
'IITD','MBA','F','F',175000 from dual union all select
'IITM','MBA','M','F',257000 from dual union all select     
'IITKH','MTech','F','P',335000 from dual union all select
'IITD','MBA','F','P',540335 from dual union all select
'IITC','MBA','F','F',125089 from dual union all select
'IITD','MTech','M','P',290756 from dual union all select
'IITM','MBA','M','P',200000 from dual union all select     
'IITKH','MBA','F','F',534990 from dual union all select
'IITD','MBA','F','P',221000 from dual ;
certain conditions of extraction are as follows-

MATTER OF STATE
College of 'IITB' and status = 'P'-'good WestRegion '.
College of 'IITC' and status = 'P'-'good SouthRegion '.
College 'IITD' and 'IITK' and status = 'P' and type = 'F' - 'female NothRegion spent.
College not in 'IITK' and status = 'F' - 'Ex Kanpur Failed'

Results-
Region Statnding     Fees
WestRegion Passed     440460
SouthRegion Passed     655000
NothRegion Female Passed     1386335
Ex Kanpur Failed     1092079
Used SQL
I use the following query that only make sure of the case, but it's not how I want to exit, if I try to use the case to breast to decode then how to work on it.
SELECT (CASE WHEN College in ('IITB') and status='P' then sum(fees) else 0 end) WP,
(case when College in ('IITC') and status='P' then sum(fees) else 0 end) SP,
(case when College in ('IITD','IITK') and gender='F' and status='P' then sum(fees) else 0 end) NFP,
(case when College in ('IITK') and status='F' then sum(fees) else 0 end) ExKF
FROM 
TT2
GROUP BY College, Class,gender,status
SELECT CASE WHEN College in ('IITB') and status='P'
                    then 'WestRegion Passed'
            when College in ('IITC') and status='P'
                    then 'SouthRegion Passed'
            when College in ('IITD','IITK') and gender='F' and status='P'
                    then 'NothRegion Female Passed'
            when College in ('IITK') and status='F'
                    then 'Ex Kanpur Failed'
            else 'Others' end region_standing,
            sum(fees) fees
FROM TT2
GROUP BY  CASE WHEN College in ('IITB') and status='P'
                    then 'WestRegion Passed'
            when College in ('IITC') and status='P'
                    then 'SouthRegion Passed'
            when College in ('IITD','IITK') and gender='F' and status='P'
                    then 'NothRegion Female Passed'
            when College in ('IITK') and status='F'
                    then 'Ex Kanpur Failed'
            else 'Others' end;

Tags: Database

Similar Questions

  • How to use the capture and the print button

    I tried to figure out how to use the capture and the "print" button, or add or what you call. I press it and the whole page of a different color changes, so I try to cut the section I want but I don't know how to send it to the printer. Can someone help me with this. I'm not at savvy with tech stuff, but when I find a recipe or something and it doesn't have an option to print a certain area, I can't understand how to use it?

    Thank you

    Andi Starbuck

    That happens to me is, I click and drag to make a rectangle of yellow selection, and as soon as I raise my finger on the mouse button, the part I've selected is captured as an image, a new tab opens and preview before printing, the image display. I can use the installation of the Page or simply print. But if I close the preview, this temporary image vanishes and I'm back on the page where I started. You see something different?

  • DV7 - 3067cl, how to open the case and clean the fan?

    Where to find a manual that shows you how to open the case to clean the fan?

    Thank you!

    Hello

    It is not easier to do component, but the procedure is detailed from on Page 94 of your & Maintenance Guide.

    Kind regards

    DP - K

  • How to use the conditional and made mandatory

    Hello

    I need to use the conditional and made mandatory something jspx page. Following line gives an error:

    rendered = "#{Bindings.type.inputValue! = 'abc' & & bindings.proofId.inputValue! ="} ' "

    Error: Name expected instead of &.

    What is the right way?



    Note: I use Jdev 10.1.3

    Boring, but you can use & #38; & #38; (remove the space after the &) for this.

    Timo

    Published by: Timo Hahn on 24.11.2009 08:46

    Published by: Timo Hahn on 24.11.2009 08:48

  • How to use the rescue and recovery and product recovery discs?

    Hello world

    I just recently became a new owner of a T61 and really enjoy. I did have a chance yet to test the hotline of lenovo, as I've not yet screwed anything up if badly needing their help. I tried a factory clean reinstall from the service partition and it worked fine. I would like to know, how one uses it the rescue and the recovery boot disk and the recovery disks of the product I created myself? From my previous experience with Dell and HP, I didn't insert the one and restart the computer, and the rest followed. But the ThinkPads, if I ever wanted to bring a State own factory using these disks, can I use with rescue and recovery first, followed by the recovery of product? I'm curious, what is the difference between the two?

    art140 wrote:

    From my previous experience with Dell and HP, I didn't insert the one and restart the computer, and the rest followed. But the ThinkPads, if I ever wanted to bring a State own factory using these disks, can I use with rescue and recovery first, followed by the recovery of product? I'm curious, what is the difference between the two?

    1. Place the rescue and recovery disc in the drive, and then restart.  This disc contains the same program that you used when you restored your system from the service partition.  Once the program is loaded, you will see the same screen with the same options as before.
    2. Choose to restore your system as you did with the service partition.  You will not see an option to do a custom restore.  When the program is run from the disk, it automatically performs a full restore.
    3. The program will rebuild the service partition and copy the program files on him.  When you are prompted, insert the product recovery disks.  The compressed system and application files contained on these discs will be copied to the new service partition.  Once the copy process is completed, your system will be restored from the service partition.
    4. After restoration, you will be able to make a new set of recovery discs if you wish.  You will also be able to do a restore custom through the service partition.

    Don

  • How to use the Fusion and my whole bootcamp partition?

    Here's what I want to do...

    I have a bootcamp with Windows XP partition on this already...  I installed merger and created a brand new Windows XP on it and everything goes smoothly.  There are times when I want to start windows in my score so I can play my games without having to run two operating systems at the same time.

    I was able to do this with Parallels for a long time, but I have since then switched.  My question is...  How to use my bootcamp with merge partition?  I just want to be able to run Fusion when I'm not playing games, and when I am, simply restart so I can get my complete resources of computers.

    Well, the reason why you did not see the Virtual Machine library window was because the Windows XP Home Edition virtual computer is configured to start automatically when the merger opens such indicated by the orange and white star.  By clicking on the orange/white star if he stops automatically load and clicking on the blue/white star it will become orange/white

    Just a little note... The CONTENT on Bootcamp is not what I want to use. I want to use Windows XP from VMWare Fusion I have done, but on the training camp of partition.

    Based on what you said it sounds like what you want to do a (Virtual, physical) V2P transfer and while this is feasible technically is not necessarily a simple process and V2P requires that the source properly prepared to be transferred to a different material and then an Image created, and then loaded into the Boot Camp partition.  It is outside the scope of his abilities and VMware Fusion and requires the use of tools 3rd party and knowledge of such a process of preforms.  IMO, if one may wonder how to do that, so it's just better than you manually rebuild the Boot Camp partition to suite your needs if the current configuration does not meet your needs.  That said a clean generation always produces a less problematic situation and provides long-term for a better overall performance however if you want to search the forum or Internet V2P or physical Virtual you can find more information on what it has been covered before.

  • How to use the onComplete and tween scale?

    It's my code.

    //width variable
    var widthSize:Number;
    var heightSize:Number;
    
    var TIMER_DELAY:Timer = new Timer(3000, 1); // 8 second delay
    TIMER_DELAY.addEventListener(TimerEvent.TIMER, EXMove);
    wedding_mc.alpha = 0;
    graduation_mc.alpha = 0;
    concert_mc.alpha = 0;
    
    function wedding():void
    {
         //trace(wedding_mc.width);
         widthSize = wedding_mc.width - 1400.15;
         heightSize = wedding_mc.height - 600;
         slideXTween = new Tween(wedding_mc, "alpha", Strong.easeOut, 0, 1, 5, true);
         slideXTween = new Tween(wedding_mc, "width", Strong.easeOut, wedding_mc.width, widthSize, 3, true);
         slideXTween = new Tween(wedding_mc, "height", Strong.easeOut, wedding_mc.height, heightSize, 3, true);
         slideXTween = new Tween(wedding_mc, "x", Regular.easeOut, 882, 499, 2, true);
         
         trace(widthSize);
    }
    function EXMove(event:TimerEvent):void
    {
         //To slide in on X axis
         slideXTween = new Tween(EX1_mc, "x", Regular.easeOut, 882, 499, 2, true);
         wedding();
    }
    
    TIMER_DELAY.start();
    

    The way I have with wedding(); does not work exactly as I wanted. So, how can I use onComplete to run the function wedding() after the EXMove is done? Secondly, the width and height of my wedding_mc are related, so, why can't I just tween only the width or the height instead of two?

    Any help is very appreciated.

    Look, they have a very good documentation that explains how to do lots of cool things. Their help is on pages that I put a link to as well in each class. Really, you should read the docs - they solve 90% of the questions. It refers to any class, it is.

    Regarding onComplete, I guess it should be:

    TweenLite.to (EX1_mc, 2, {x: 882, onComplete: wedding});

  • How to use the swf and pictures as a hypertext link to specific slides when you click

    How to use swf and images as a link hypertext to specific slides when clicked.i average as a buttons.

    Hello

    The key is that you can not!

    What you * CAN * do, however, is to create the illusion that they establish between these objects. What you do is use a box click object which has been placed on top or in front of the Image or SWF file.

    See you soon... Rick

    Useful and practical links

    Captivate wish form/Bug report form

    Certified Adobe Captivate training

    SorcerStone blog

    Captivate eBooks

  • Satellite M30X-122: how to use the headphones and speaker at the same time?

    Hello

    y at - it a possiblity to use headphones and speaker at the same time?
    When I plug the headphones into the Jack, the speaker is created off the coast of the moment.

    Thank you
    Peter

    Hi Peter,.

    There is unfortunately no way to use both headphones and speakers at the same time. This is because tghere's a disconnection physical power for the internal speakers when you plug in the headphones. It is not by software. The only way around this would be to dismantle the headphones Jack and solder connections that are broken when you insert the headphone permanently.

    Kind regards

  • How to use the battery and the power cord in a smart way?

    Is it possible to do a power management, that use the battery as long as there is power in the battery and the first when there is no more power use the external power supply, which has been active all the time without loss of battery charge?

    Batteries wear out with use.  And they can wear out more when you do not use unless you physically remove them.  If you travel a lot, you will have to bite the bullet and buy new batteries every two years.  If you are usually connected to a power outlet, remove the battery and it will last much longer.  For more details, refer to the User Guide.  Different brands and models my vary in their recommendations.

    Good luck.

  • Help: How to use the Case statement in the ODI11g Interface?

    Hello
    My basic source I get 'Year' values and I want that these values result code in the interface and after translation want to push on the target system.
    Example:
    Database source, I get value for
    Year
    2010
    2011
    2012

    When I get the year 2010 I want to change the value in "FY10".
    When I get year 2011 I want to change the value in "FY11.
    and even for the year 2012 to "FY12.
    I've tried to make the Case statement, but had no success.
    I don't want to create the lookup table in the source system.
    Any help in this matter.

    Thank you

    Concerning
    Sher

    Published by: Sher Ullah Baig on August 26, 2012 17:52

    CASE
    WHEN source_column = '2010' THEN 'FY10.
    WHEN source_column = '2011' and THEN 'FY11.
    WHEN source_column = '2012' and THEN 'FY12.
    END

  • How to use the case for this query.

    I got this name from the Employee table.
    columns...

    EmpId,
    EmpType,
    Join date,
    Date of resignation

    Now in EmpType it can be either 'P' OR 'C '.

    So I want to check if the EmpTYpe is 'P' then joiningdate must not be null
    and if the EmpType is 'C' then resignation date must not be null.

    So only want to employee records.
    Help, please.

    Select * from employee
    where (employeetype = 'c' and joinngdate is not null)
    or (employeetype = 'p' and resigndate is not null)

  • How to use the extension and they are safe to use?

    Hello

    I intend to use firefox for iMac in order to get the benefits of extensions. Extensions that I use are the visited site speed measure. I am currently using gtmetrix for my site http://www.i-phony.com , I was told that it gives results from remote servers.

    My server is located in Saudi Arabia. Will be extensions of what the speed of the server measure be safe to use. And are they able to give an accurate reading of the place where I am?

    your support is much appreciated.

    Best regards

    Each addon at AMO avaible were examined and is safe to use.

  • How to use the case to replace the & in the select statement

    Oracle version: 11.1.0.6.0
    RHEL

    Hello

    I want to get a list of all users that are expired and locked, but want to replace '&' with and here is my code but it does not work.
    Please some advice, thanks.

    SQL > select username,.
    2 cases (account_status as 'EXP %' then "A UP AND LOCKED"
    3 ELS 'no locked user '.
    4 end) account_status
    5 of dba_users
    6 where account_status as "EXPI % ';
    case (account_status as 'EXP %' then "A UP AND LOCKED"
    *
    ERROR on line 2:
    ORA-00907: lack of right parenthesis

    Hello
    Can u try like this

    Select the username, account_status,
    cases where account_status like 'EXP %' then 'A EXPIRED AND LOCKED'
    End ELSE Account_status "account_status.
    from dba_users
    where account_status as "EXP % ';

    concerning
    srikkanth. M

  • use the queue and event to read data from two series mean

    Hi all

    I'm reading the data of two serial port using QUEUE AND EVENT but not sccusess. can someone help me?

    I use LABVIEW 2011.

    att my project.

    regrads.

    You stop the second for loop using cluster of error which means that your upper and lower loop stops when you press exit but not the one in the middle. In theory, you should send a queue for loops below when you press the exit button and also make sure that you shoot hunting all queues before closing everything.

Maybe you are looking for