How to make the query in one single query? No Union please....

Hi,
I have sets of around 18 queries which is finding counts in many scenarios. I wanted to have a single query for this. which diplays the result in a single row.Is there a way , I heared analytical functions are good options ,but I am new to Oracle . Please help me.
select count(*) total_count from emp; --100
select coun(*) MGR_count from emp where job='MGR'-- 10
select count(*) dept_count from emp where deptno in(10 ,20)-- 75
output..
TOTAL_COUNT     MGR_COUNT      DEPT_COUNT
100                                   10             75
Thanks

This:
select count(*) total_Count
      ,count(decode(job,'MGR',1,null)) mgr_count
      ,count(case when deptno in (10,20) then
               1
             else
               null
             end
            ) dept_count
from emp;
untested

Similar Messages

  • How to read the child elements in single query

    Hi
    How to read the child elements under 'alternateIdentifiers' and 'matchEntityBasic' in a single query followiing xml content.xml content is of xmltype
    I/p doc
    <UPDATES>
    <matchEntity>
    <sourceUpdateId>SAMSUNG</sourceUpdateId>
    <matchEntityId>861873</matchEntityId>
    <alternateIdentifiers>
    <sourceUpdateId>SAMSUNG</sourceUpdateId>
    <schemeCode>SMG</schemeCode>
    <effectiveDate>2012-01-16</effectiveDate>
    </alternateIdentifiers>
    <alternateIdentifiers>
    <sourceUpdateId>SAMSUNG</sourceUpdateId>
    <schemeCode>TEBBGL</schemeCode>
    <effectiveDate>2012-01-16</effectiveDate>
    </alternateIdentifiers>
    <matchEntityBasic>
    <sourceUpdateId>SAMSUNG</sourceUpdateId>
    <marketExchangeCode>XASE</marketExchangeCode>
    </matchEntityBasic>
    </matchEntity>
    </UPDATES>
    o/p
    sourceUpdateId schemeCode effectiveDate marketExchangeCode
    SAMSUNG SMG 2012-01-16 XASE
    SAMSUNG TEBBGL 2012-01-16
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    i tried the query but not working
    SELECT sourceUpdateId ,schemeCode ,effectiveDate ,marketExchangeCode FROM message pl,XMLTABLE ('/UPDATES/matchEntity/alternateIdentifiers'
                   PASSING pl.messagetext
                   COLUMNS sourceUpdateId VARCHAR2 (20) PATH sourceUpdateId,
                   schemeCode VARCHAR2 (20) PATH 'schemeCode',
              effectiveDate DATE PATH 'effectiveDate',
    marketExchangeCode VARCHAR2 (20) PATH './matchEntityBasic/marketExchangeCode'
    ) x
    iam not retriving marketExchangeCode with the following query
    marketExchangeCode VARCHAR2 (20) PATH './matchEntityBasic/marketExchangeCode'
    thanks

    The problem is that "matchEntityBasic" is not a child of "alternateIdentifiers", so this :
    ./matchEntityBasic/marketExchangeCodepoints to nothing.
    To display both values in the same query, you'll need a two-level approach.
    For example :
    SQL> SELECT x2.sourceUpdateId
      2       , x2.schemeCode
      3       , x2.effectiveDate
      4       , x1.marketExchangeCode
      5  FROM message pl
      6     , XMLTable(
      7         '/UPDATES/matchEntity'
      8         passing pl.messagetext
      9         columns marketExchangeCode   VARCHAR2(20) PATH 'matchEntityBasic/marketExchangeCode'
    10               , alternateIds         XMLType      PATH 'alternateIdentifiers'
    11       ) x1
    12     , XMLTable(
    13         '/alternateIdentifiers'
    14         passing x1.alternateIds
    15         columns sourceUpdateId     VARCHAR2(20) PATH 'sourceUpdateId'
    16               , schemeCode         VARCHAR2(20) PATH 'schemeCode'
    17               , effectiveDate      DATE         PATH 'effectiveDate'
    18       ) x2
    19  ;
    SOURCEUPDATEID       SCHEMECODE           EFFECTIVEDATE MARKETEXCHANGECODE
    SAMSUNG              SMG                  16/01/2012    XASE
    SAMSUNG              TEBBGL               16/01/2012    XASE
    Or the shorter version :
    SQL> SELECT x.sourceUpdateId
      2       , x.schemeCode
      3       , x.effectiveDate
      4       , x.marketExchangeCode
      5  FROM message pl
      6     , XMLTable(
      7         'for $i in /UPDATES/matchEntity
      8          return
      9            for $j in $i/alternateIdentifiers
    10            return element r { $j/child::*, $i/matchEntityBasic/marketExchangeCode }'
    11         passing pl.messagetext
    12         columns sourceUpdateId     VARCHAR2(20) PATH 'sourceUpdateId'
    13               , schemeCode         VARCHAR2(20) PATH 'schemeCode'
    14               , effectiveDate      DATE         PATH 'effectiveDate'
    15               , marketExchangeCode VARCHAR2(20) PATH 'marketExchangeCode'
    16       ) x
    17  ;
    SOURCEUPDATEID       SCHEMECODE           EFFECTIVEDATE MARKETEXCHANGECODE
    SAMSUNG              SMG                  16/01/2012    XASE
    SAMSUNG              TEBBGL               16/01/2012    XASE

  • How to make the color of one picture to be the same as another one

    I want to change the orange color of this button:
    to the dark blue(at the top) of this logo,
    How could I do this? I am not that familiar with photoshop, please show me the detailed steps if it is possible, thanks

    Hi there
    Below are instructions on how to recreate the gradient effect of the orange button using the dark blue color from the logo. It is difficult to change the color of a flattened gradient like the one in the orange button. However, recreating the button is a fairly simple process.
    Step 1: Open both the button and the logo in Photoshop.
    Step 2: Go to the logo image and select the Eyedropper tool from the tool bar, highlighted below. Then, click on the dark blue color in the logo.
    Step 3: Go back to the button image and go to your Layers Panel. Create a new layer using the icon highlighted below.
    Step 4: From the tool bar, select the Paint Bucket Tool, located directly below the eraser tool. If you don't see it, click and hold on the gradient tool and a submenu should pop out. With the Paint Bucket Tool selected, click on the canvas area to fill it with the dark blue color from the logo.
    Step 5: Create a new layer from the layers panel using the same process as Step 3.
    Step 6: Click and hold on the Paint Bucket Tool and select the Gradient Tool from the tool bar, as shown below.
    Step 7: At the top of your window, you should see the Gradient Tool menu. Select a transparent linear gradient, using the settings highlighted below.
    Step 8: Click on the dark bue color swatch in your toolbar to bring up the Color Picker dialog box. Drag the white circle in the color field to the upper left corner to select white. Click OK when you are done.
    Step 9: Now you can apply the gradient by clicking and dragging up over the button. Hold the shift button on your keyboard as you drag to create a perfectly vertical line. To create the gradient below, I started from just outside the canvas area and stopped around the middle of the button. This might take a few tries - if you mess up, hit control-Z (Windows) or command-Z (Mac) on your keyboard to undo.
    Step 10: Now that you have your gradient, go to the layers panel and use the Opacity slider in the upper right hand corner of the layers panel to reduce the opacity of the gradient.
    Step 11: Now you can delete the orange button layer by selecting the layer and clicking the delete icon shown below.
    There you go! Now you can save your button and use it as you'd like. If you ever need to change the color, just select the dark blue layer and use the paint bucket tool to fill it with whatever color you want. Below I have included a side-by-side comparison with the original orange button.
    If you have any further questions or need clarification, just ask!
    Good luck!

  • How to make the messages from ONE contact only sil...

    Hello,
    is there any way, even with paid 3rd party software, to make the messages that come only from one contact silent? That means that i want to have the profil to outdoor or general or whatever, when people call me or send me messages the phone to ring, when the contact X will call me to ring, but when this particular contact X send me messages the phone to be silent.
    I have the nokia E6-00

    http://www.apple.com/feedback/iphone.html

  • VPD - How to make the where clause a correlated query

    Hi,
    My VPD function has the following where clause:
    where_clause:= ' project_id in (select object_id from pa_project_classes p'||
    ' where p.class_category='||''''||l_cat||''''||
    ' and p.CLASS_CODE='||''''||l_class||''''||
    ' and p.OBJECT_TYPE=''PA_PROJECTS'''||
    The problem is that the subquery is not using the unique key defined on the table pa_project_classes. What I need is something as follows:
    where_clause:= ' project_id in (select object_id from pa_project_classes p'||
    ' where p.class_category='||''''||l_cat||''''||
    ' and p.CLASS_CODE='||''''||l_class||''''||
    ' and p.OBJECT_TYPE=''PA_PROJECTS'''||
    ' and p.object_id=mainquery.project_id ||
    The problem is that since the table pa_project_classes also has a column project_id, I have to prefix the column name by the alias of the main query like 'mainquery.project_id'. However this seems impossible as main query is not unknown .
    I would be grateful if you could suggest any workaround or solution.
    Thanks

    Just have a look over these two statements if it solves your problem
    one time where clause
    Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
    dynamic where clause
    set_block_property('BLOCK_NAME'default_where, your form itme)
    you can where clause at run time from any procedure or some triggers

  • How to make two tables from one single taable

    Hi,
    i have one table with 100 records and i want to create two tables each with 50 records and with no duplicates. if i will do on bases on empno then i have to check the min and max emp no and then divide them in two tables, is there any automate way of performing this task.
    Regards,
    Abida

    Hi,
    A rather quick and dirty solution, but definitely works.
    I used the HR sample schema (employees table) for this.
    hsaprd@706447>create table tab1 as select * from employees where rownum <51;
    Table created.
    hsaprd@706447>select count(*) from tab1;
    COUNT(*)
    50
    hsaprd@706447>create table tab2 as select * from employees where employee_id nnot in (select employee_id from tab1);
    Table created.
    hsaprd@706447>select count(*) from tab2;
    COUNT(*)
    56
    hsaprd@706447>
    Hope this helps!
    -Anand

  • How to make the result showing one time and make the result to csv file?

    My script having problem of showing out all the AD computer name result  from Active Directory once when running it and storing the result to csv file. I am a newbie in AD and powershell.
    This is the code:
    $strADPathFile = "D:\Powershell for AD\ADPathList.txt"
    $strErrLogFile = "D:\powershell for AD\errorADComputer.log"
    $arrADPath = Get-Content -Path $strADPathFile
    foreach ($strADPath in $arrADPath)
    try
    $objSearch = New-Object DirectoryServices.DirectorySearcher
    $objSearch.Filter = '(objectCategory=computer)'
    $objSearch.SearchRoot = $strADPath
    $objSearch.SearchScope = "Subtree"
    $objSearch.PageSize = 1000
    $objResults = $objSearch.Findall()
    write-host "Retrieving AD computer information in the domain $strDomain"
    write-host "Number of AD Computer Name result: "$objResults.Count
    foreach($objResult in $objResults){
    $objComputer = $objResult.GetDirectoryEntry()
    write-host $objComputer.dNSHostName
    try
    # InsertSQLTable $objComputer
    catch
    write-host $error[0]
    $strError = $objComputer.dNSHostName + " " + $dateNow + $error[0]
    Add-Content $strErrLogFile $strError
    catch
    write-host $error[0]
    Export-Csv D:\PowerShellforAD\test2.csv
    This is the error that I had get is that it will get the result for 2nd time again.
    By the way, what is InputObject about? I had research some of it and still did not quite get it. Can anyone explain? Thanks 

    Hi,
    in the final line you call Export-Csv. which is a great command at exporting information. However, for it to work it needs a path to export to (D:\PowerShellforAD\test2.csv in your case) and Information (InputObject) to export.
    You do not give that command any Information, so it throws an error.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • When I run a web browser immediately loaded two blank tabs. How to make the browser load the only one?

    when I run a web browser immediately loaded two blank tabs. How to make the browser load the only one?

    Did you check the home page setting to make sure that if doesn't have pipe (|) symbols?
    See these articles for some suggestions:
    *https://support.mozilla.org/kb/Firefox+has+just+updated+tab+shows+each+time+you+start+Firefox
    *https://support.mozilla.org/kb/How+to+set+the+home+page - Firefox supports multiple home pages separated by '|' symbols
    *http://kb.mozillazine.org/Preferences_not_saved

  • TS2755 Is there a fix to deleting already deleted address book contact, from messages search? i.e. when you type in say letter c in messages search, all contact with a c, past already deleted and current all appear?  How do you make the old deleted ones a

    Is there a fix to deleting already deleted address book contact, from messages search? i.e. when you type in say letter c in messages search, all contact with a c, past already deleted and current all appear?  How do you make the old deleted ones appear?

    only way is to restore the phone as new.  OR wait until IOS 7 comes out in the fall.

  • How to make the contact picture should appear on the upper right corner with thumb picture when some one calling instead showing the entire screen

    How to make the contact picture should appear on the upper right corner with thumb picture when some one calling instead showing the entire screen

    See deggie's response in this post... https://discussions.apple.com/message/8531821#8531821

  • How do you make the background all one color without disturbing the subjects?

    I shot a wedding this past weekend.  Where the bridal party walked in there was an acrhway with christmas lights as the only lights.  It made the background all splotchy.  I have tried the paintbrush tool, but only preset choices, such a textures and such.  Won't help.  I need to work around people and make the background all one color.  I've tried using a vignette, but it made it too dark, and when you lighten the exposure you see all the splotches.  Does anyone have any advice.  I am in a  jam, I want the colors to be uniform for all the bridal party....and not look like someone threw paint on the wall.  HELP PLEASE!
    I'm using Adobe Photoshop Elements 10.

    You'll need to post an example so we can figure out the best way.
    Ken

  • How can I get the same result using single query?

    There are 3 tables
    1) tool_desc -
    a master table for storing tool records,
    columns tool_no, tool_chg,
    # of records = 1.5 Millon
    2) step_desc -
    a master table for storing plan wise step records,
    columns plan_id, step_key,
    # of records = 3700 Million
    3) step_tool - a transaction table storing tools to the steps,
    columns plan_id, step_key, tool_no, tool_chg
    For each step in the step_desc table, I need to randomly fetch 1 to 50 tools from tool_desc and insert them into step_tool table.
    Using PL/SQL block, it is like the following -
    begin
    for x in (select plan_id, step_key from step_desc) loop
    insert into step_tool(
    plan_id,
    step_key,
    tool_no,
    tool_chg)
    select
    plan_id,
    x.step_key,
    tool_no,
    tool_chg
    from
    tool sample(0.1)
    where
    rownum <= trunc(dbms_random.value(1,51))
    commit;
    end loop;
    end;
    I need to do the same using a single query so that I can use the CTAS (create table as select) statement and load the data as a bulk.
    Can I do that?

    If they have parent child releation, you can use connect by prior clause,

  • Tricky SQL query... how to get all data in a single query?

    create table employee_definition (def_id number, def_name varchar(50));
    insert into employee_definition values (100, 'EMAIL');
    insert into employee_definition values (200, 'MOBILE_PHONE');
    insert into employee_definition values (300, 'HOME_PHONE');
    SQL> select * from employee_definition;
        DEF_ID DEF_NAME
           100 EMAIL
           200 MOBILE_PHONE
           300 HOME_PHONE
    create table employee_data (def_id number, def_value varchar(20), emp_id number);
    insert into employee_data values (100, '[email protected]', 123);
    insert into employee_data values (200, '01232222', 123);
    insert into employee_data values (300, '5555', 123);
    insert into employee_data values (100, '[email protected]', 666);
    insert into employee_data values (200, '888', 666);
    insert into employee_data values (300, '999', 666);
    insert into employee_data values (300, '444', 777);
    SQL> select * from employee_data;
        DEF_ID DEF_VALUE                EMP_ID
           100 [email protected]              123
           200 01232222                    123
           300 5555                        123
           100 [email protected]              666
           200 888                         666
           300 999                         666
           300 999                         777
    7 rows selected.I'm supposed to create a SQL that will return me the email, mobile_phone, and home_phone for a set of employees. The result will be something like this:
    EMPLOYEE ID | HOME_PHONE | MOBILE_PHONE | EMAIL
    123         |  5555  |    01232222      | [email protected]
    666         |  999  |    888      | [email protected]
    777         |  444  |    null     | nullThe thing I'm finding difficulty here is that the same column is used to store different values, based on the value in employee_definition table (something like a key/value pair). If I do:
    SQL> select emp_id, def_value as email from employee_data, employee_definition
      2  where employee_data.def_id = employee_definition.def_id
      3  and employee_definition.def_name = 'EMAIL';
        EMP_ID EMAIL
           123 [email protected]
           666 [email protected]'s partially ok.. I'm just getting the definition for 'EMAIL'. But how can I get all the values in a single query, knowing that the column stores different values based on def_name?

    Oh no, not again.
    Entity attribute models always seem like a great idea to people who have been in the profession for five minutes and lack any kind of fundamental knowledge.
    It staggers me that someone with 2,345 posts still believes "you need a 'detail table' for [storing multiple telephone numbers]"
    "A person can have multiple telephone numbers" is not an excuse to build a tired person_attribute table. Niether is the bizarre proposal by someone with over 4k posts who should know better in an earlier post that EAV models are necessary to support temporal fidelity.
    Taken to it's logical conclusion, EAV modelling leads to just two application tables. THINGS and THING_ATTRIBUTES. And when you consider that a THING_ATTRIBUTE is also a THING, why not roll those two tables up into one also? Hmmm, what does THINGS and THING_ATTRIBUTES look like? I know, TABLES and COLUMNS. Who would've guessed? SQL already provides the completely flexible extensible attribute model the advocates of EAV proscribe. But it also has data types, physical data independence, constraints and an efficient query language which EAV does not.
    EAV modelling errodes the semantics of the attributes which are bundled into the "attribute" table.
    There is no point in storing 12 different phone numbers with implied functional dependency to unconstrained and often repeating notional attributes like "MOBILE", "LANDLINE", "WORK", err, "WORK2", err, "MOBILE2", err, ... when this phone type attribute has no semantic value. When you want to call someone, you invariably want to retrive the prefered_phone_number which may depend on a time of day, or a call context.
    These things need to be modelled properly (i.e normalised to BCNF) within the context of the database.

  • How to make the calculation or formula in bottom of the coloum

    How to make the calculation or formula in bottom of the coloum in Discoverer report.
    Regadrs
    Manikandan

    Hi Ros
    You have a couple of issues, one that is simple to resolve and one that is not so simple.
    First, the simple one - the word TOTAL. To alter the word that Discoverer inserts next to a total, or to even remove the word altogether, use this workflow:
    1. Right-click on the total and from the pop-up menu select Edit Total
    2. At the bottom right-hand corner of the Edit Total dialog box is the area where the label is maintained. You will see a checkbox for the label
    3. If you uncheck the label you can change the label to anything you like, including nothing
    4. After you have set the label, click OK and close the Edit Total dialog box
    Note: In Desktop, this is done via a drop-down from the Total dialog box. If you click the drop-down, the last item in the list is called Generate Label Automatically. If you uncheck this you can create your own label.
    Your second issue concerning the non-totaling of the grand total on some items means that there is something preventing one or more of the totals from calculating. First of all, try to determine which item or items is causing the problem by adding individual totals to each of the desired columns. You will eventually find the column which has the culprit. If you use the above workflow to suppress the display of any labels your total line will look as though you have totaled all items.
    Next, having found the column that will not total, try to figure out why the values will not add up. Could the column be a calculated item? If so, it is possible that you have used SUM on the outside of the calculation, like this:
    SUM(some item - some other item) - this will not total if the original items themselves are in the query and are also being summed. This is because you are mixing aggregate and detail items within the total.
    Try changing the formula like this:
    SUM(some item) - SUM(some other item) and see if this helps.
    If this is not the cause then try changing the formula for that column's total to CELL SUM instead of SUM. This causes Discoverer to literally add the values in the column.
    If this is not the cause, could you possibly be trying to total repeated values? By default, this is disabled in the later versions of Discoverer. The repeated values will be caused if you have multiple joins in your query and the item that you are totaling is from the many end of a one to many relationship. Suppose you had items from a header table and line table in the same worksheet with there being multiple lines for the same header, and now let's say you have a column which is returning something from the header. That value will get repeated and if you try to total it would generate the wrong answer, hence out of the box Discoverer is trying to protect you from yourself.
    However, it could be that the column really should be totaled but because Discoverer has detected a one to many join it will not total that column. To prove that this is the reason, change the join from a one to many to a one to one. Don't worry, this won't stop the query from working. If this allows the total to work then you can either leave the join as it is with a one to one, which won't harm Discoverer or you can edit the pref.txt on the server and change one of the preferences.
    The preference I would change is called AllowAggregationOverRepeatedValues. By default this is disabled and will be set to 0. Changing this to a 1 will now tell Discoverer that repeated values can now be totaled. Don't forget to apply the preferences correctly by execiting applypreferences.bat, on Windows or applypreferences.sh, in Linux or Unix, and then stopping and restarting the Discoverer server.
    I hope this helps
    Best wishes
    Michael Armstrong-Smith
    URL: http://learndiscoverer.com
    Blog: http://learndiscoverer.blogspot.com

  • How to make the label UI Element as mantatory?

    please help me how to make the inputfield for the label (say id) as mantatory one?
    Thanks in advance

    Hi Alagappan ,
           To make any field mantatory you have do coding requiered for input check.
    For user visibility you can make a field required by changing the state of your UI element to required.
    In normal Input Fields the asterisk will come on the left of the input field,
    It will be basically on the right hand side of the label having label for property bound to the input field.
    It will be like
    Name * = |''''''''''''''''''''''''''''''''|
    But that is just for visibility purpose.
    To make it mandatory you need to do some coding during the save or validate or final action on the screen
    like :-
    data lo_nd_employee type ref to if_wd_context_node.
    data lo_el_employee type ref to if_wd_context_element.
    data ls_employee type wd_this->element_employee.
    data lv_pernr like ls_employee-pernr.
    navigate from <CONTEXT> to <EMPLOYEE> via lead selection
    lo_nd_employee = wd_context->get_child_node( name = wd_this->wdctx_employee ).
    get element via lead selection
    lo_el_employee = lo_nd_employee->get_element( ).
    get single attribute
    lo_el_employee->get_attribute(
    exporting
    name = `PERNR`
    importing
    value = lv_pernr ).
    *Check the input here
    If lv_pernr is initial.
    get message manager
    data lo_api_controller type ref to if_wd_controller.
    data lo_message_manager type ref to if_wd_message_manager.
    lo_api_controller ?= wd_this->wd_get_api( ).
    call method lo_api_controller->get_message_manager
    receiving
    message_manager = lo_message_manager
    report message
    call method lo_message_manager->report_error_message
    exporting
    message_text = u2018Please input the personnel Numberu2019
    Reply if you required any further assistance.
    Thanks & Regard ,
    Monishankar C

Maybe you are looking for

  • I am unable to restore my backups from my Time Machine

    MacBook Pro – My reformatted system that won't restore from my time machine - HELP PLEASE I loaded Lion when it first came     out and all my troubles started. (It was the same on my 24” iMac).     Mail particularly hardly worked on either machine af

  • Error in replicat when updating a row

    Oracle 11gR2 OGG 11.1.1.1.5 I am getting the following error when updating a row that exists in both the target and source db: OCI Error ORA-01403: no data found, SQL <UPDATE....The following is in the discard file: Record not found Mapping problem w

  • Formula Node or problem

    Hi, I'm having a problem using the formula node. The output variable is always 1, but I notice that if the code was: if(N != 1) L = 1; else L = 0; The program work ok. Thanks, Sílvia Attachments: 1.png ‏5 KB 1.png ‏5 KB

  • Email notifications, Hidden Names

    When I have tried the feedback forum before, I have had no response, but will try again regarding a few points: E-mail notifications appear to be working again after a long absence, but they no longer contain a link to the forum thread, which is very

  • Inserting a newline using RandomAccessFiles

    Hi, Im trying to insert a new line halfway throug a text document using randomAccessFile but java wont allow me to use RandomAccessFile fw = new RandomAccessFile( FileName, "rw" ); fw.seek(Pos[0]); fw.write(System.getProperty("line.seperator"));it al