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

Hello

I have a series of about 18 queries that find charges in many scenarios. I wanted to have a single query to do this. which displays the result in a single line. Is it possible, I heard analytical functions are good options, but I am new to Oracle. Please help me.

Select count (*) total_count emp; -100

Select coun (*) MGR_count emp where job = "MGR" - 10

Select count (*) dept_count emp where deptno in (10,20) - 75

output...

----------

TOTAL_COUNT MGR_COUNT DEPT_COUNT
100                                   10             75

Thank you

Hello

Here's one way:

SELECT COUNT (*) TOTAL

, COUNTY (CASE job WHEN = END "MGR", 1) AS mgr_count

, COUNT (CASE WHEN deptno IN (10, 20) THEN 1 END) AS dept_count

FROM table_x

;

Instead of putting the conditions in a clause WHERE (where they would exclude whole lines), put the conditions in a CASE expression, where they affect only this column.

Tags: Database

Similar Questions

  • How to make the query more efficient

    Hi all

    I use the following query in my app that works very well. Although I'm not an expert in PL/SQL, can someone please suggest how can I make the query more efficient? Because I use the same contract for every query table. Only difference is that in the name of the condition column. Again I am showing same column comments for each request. I was wondering if I can join these 3 and do 1 single request if possible

    DECLARE
    v_CONTRACTNO varchar2(100);
    v_CHILDCONTRACTNO varchar2(100);
    v_SOURCESYSTEM varchar2(100);
    
    BEGIN
    begin
    SELECT comments
    into v_CONTRACTNO
    from user_col_comments
      where TABLE_NAME = 'CONTRACT'
    and COLUMN_NAME = 'CONTRACTNO';
    end;
    begin
    SELECT comments
    into v_CHILDCONTRACTNO
    from user_col_comments
      where TABLE_NAME = 'CONTRACT'
    and COLUMN_NAME = 'CHILDCONTRACTNO';
    end;
    begin
    SELECT comments
    into v_SOURCESYSTEM
    from user_col_comments
      where TABLE_NAME = 'CONTRACT'
    and COLUMN_NAME = 'SOURCESYSTEM';
    end;
    END;
    

    Thanks in advance...

    Concerning

    Nabila

    Hi, Nabila,

    The nabila Islam wrote:

    Hi all

    I use the following query in my app that works very well. Although I'm not an expert in PL/SQL, can someone please suggest how can I make the query more efficient? Because I use the same contract for every query table. Only difference is that in the name of the condition column. Again I am showing same column comments for each request. I was wondering if I can join these 3 and do 1 single request if possible

    1. DECLARE
    2. v_CONTRACTNO varchar2 (100);
    3. v_CHILDCONTRACTNO varchar2 (100);
    4. v_SOURCESYSTEM varchar2 (100);
    5. BEGIN
    6. Start
    7. SOME comments
    8. in v_CONTRACTNO
    9. of user_col_comments
    10. where TABLE_NAME = 'CONTRACT '.
    11. and COLUMN_NAME = 'CONTRACTNO ';
    12. end;
    13. Start
    14. SOME comments
    15. in v_CHILDCONTRACTNO
    16. of user_col_comments
    17. where TABLE_NAME = 'CONTRACT '.
    18. and COLUMN_NAME = 'CHILDCONTRACTNO ';
    19. end;
    20. Start
    21. SOME comments
    22. in v_SOURCESYSTEM
    23. of user_col_comments
    24. where TABLE_NAME = 'CONTRACT '.
    25. and COLUMN_NAME = 'SOURCESYSTEM ';
    26. end;
    27. END;

    Thanks in advance...

    Concerning

    Nabila

    Of course, you can get all 3 values in a query.  Here's one way:

    SELECT contractno, childcontractno, sourcesystem

    IN v_contractno, v_childcontractno, v_sourcesystem

    Of user_col_comments

    PIVOT (MIN (comments)

    FOR column_name IN ('CONTRACTNO' AS contractno

    'CHILDCONTRACTNO' AS childcontractno

    'SOURCESYSTEM' AS sourcesystem

    )

    )

    WHERE table_name = 'CONTRACT '.

    ;

    But I doubt that it makes things very slow.   If your PL/SQL performance is poor, I suspect that the cause is somewhere that you haven't posted.

  • How to make the query AS a parameter inside... ?

    Hello all :)

    I want to create the view object, where the query using oracle AS with the value of the parameter inside (variable binding), like this:

    SELECT WhLokasi.LOKASI_ID,
    WhLokasi.DESKRIPSI,
    WhLokasi.BARIS_KE,
    WhLokasi.KOLOM_KE,
    WhLokasi.SUBKOLOM_KE
    OF WH_LOKASI WhLokasi
    WHERE AS WhLokasi.DESKRIPSI * 'setting' * AND WhLokasi.BARIS_KE AS * 'parameter. "

    someone help me... Please... : d

    THX
    agungdmt

    Hi agungdmt,

    You have several options which are all explained in the developersguide.

    First use a bindvariable and encode the LIKE statement in the where clause of your viewObject (Dev Guide Chapter 5.10.1 how to add Variables to link to a definition of view object).
    It also shows an example

    select PERSON_ID, EMAIL, FIRST_NAME, LAST_NAME
    from PERSONS
    where (upper(FIRST_NAME) like upper(:TheName)||'%'
    or upper(LAST_NAME) like upper(:TheName)||'%')
    and PERSON_ID between :LowUserId and :HighUserId
    order by EMAIL
    

    Second option is to create and use named viewCriteria (5.11.1 how to create named view declaratively criteria).

    Third, and I think that this is not what you need at the present time, is to add where clause when executing (5.10.5 How to add a WHERE Clause with named Bind Variables when running)

    If I where you, I would choose the first or second option.

    Good luck

    Luc Bors

  • How to make the icons of programs appears on the screen of windows 8

    Hi Thunderlight, you helped me with my last request and thank you again now I have another question that you might be able to help me with.  How to make the icons of programs appears on my screen of windows 8?  I had to download the debut8 when I had windows 8 so I would have the appearance of windows 7 until I have to use Windows 8.  And some of my icons of windows 7 on my windows 8, but not all.  How to go on my windows screen 8 tiles?   I now get more usage of windows 8 and use it more now so would like all my original programs that I had with windows 7 on my windows 8 as it is now tile.  I thank you and hope you can help.

    Hi Laura,

    In theory, when you switch from an earlier version of Windows to Windows 8 - as your installed applications are kept by the upgrade process, except those who are not compatible - you should find all your apps in Windows 8.

    If they all do not appear on your start screen follow these steps to pin them there:

    • [Win] + C
    • Search
    • Click anywhere in the top middle of the screen to hide the charm bar

    All installed applications are displayed. They do not necessarily correspond on a single screen to use the horizontal "lift" to bottom of the screen to move to the right / left

    • Right-click on an application, you want to pin to the start screen
    • Click on Pin to Start at the bottom left of the screen

    You are finished. A mosaic of this application is available on the start screen.

    If there is an application, you are sure is installed on your PC and you don't think through the steps made me know - there will be more complex...

    If you install a new application under Windows 8 the corresponding tile is automatically added to your start screen.

    Hope this helps

    See you soon

    LZ.

  • How to write the query option in expdp

    Hi Please someone help me how to write the query option in expdp... .in expdp using the query option...

    where AM columnname between 5 May 12 02:57:00.000' and ' 02:59:59.999 6 May 12: ';


    Please do what is necessary...

    Pavan Kumar says:
    QUERY = (columnname scott.test: "where between 5 May 12 02:57:00.000 h ' and ' 6 May 12 AM 02:59:59.999'")

    Who will fail in databases, because you assume nls_date_format. How it is difficult to put to_date() surround channels? Rather than play with quotation marks, using one parfile thusly.

    query=table_owner.table_1:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    query=table_owner.table_2:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    query=table_owner.table_3:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    

    You do not have to have all the clauses in a single line, as they are side by side parfile, which would be enough. For this reason parfile is better than the command line in order to avoid all the back-citing dance.

  • Can you please tell me how to make the thicker arrows on the Pages.

    Can you please tell me how to make the thicker arrows on the Pages. Thank you very much. There is something incredibly simple to do, but I, having a disconcerting brain, am totally unable to understand. Please please help me. Thank you

    < re-titled by host >

    Try here > Pages for Mac: Add and edit forms

  • How to make the top sites page appears when I open a new tab? Why have I not of "buttons" to pin a top site of the page tab?

    When I open a new tab, NO best sites don't show up... shows just a search engine box. I have Firefox 33.0. Why is there no 'pin' button when I opened a new page? How to make the top sites page appears when I open a new tab?

    Here is some additional information on the configuration of the new tab page:

    (1) in a new tab, type or paste Subject: config in the address bar and press ENTER. Click on the button promising to be careful.

    (2) in the search above the list box, type or paste newtab and make a pause so that the list is filtered

    (3) double-click the preference browser.newtab.url and enter your favorite page:

    • (Default) page thumbnails = > subject: newtab
    • Blank tab = > subject: empty
    • Built-in Firefox homepage = > topic: welcome
    • Any other page = > full URL of the page

    Press Ctrl + t to open a new tab and check that it worked. Fixed?

    Some traps:

    If Firefox will not let you change this setting: you can have what is called SearchProtect on your system.

    Firefox if allows you to save your changes, but he doesn't know: one of your extensions may be the substitution of her. You can consult, disable and/or remove extensions on the addons page:

    "3-bar" menu button (or tools) > Add-ons > in the left column click on Extensions

    If the modification works during your session, but during the next startup is leads to: you could have a user.js file in your personal settings Firefox (your Firefox profile folder). This article describes how to track down and delete the file: How to fix preferences that will not save.

    A little luck?

  • the sign less, shrink, &amp; out the buttons at the top right of the page is missing? How to make a comeback. In their place, it is only black?

    the sign less, shrink, & out the buttons at the top right of the page is missing? How to make a comeback. In their place, it is only black? I can click where I know everyone is & it works, but I need to be able to see them. Thanks for your help.


  • I have associated my pencil to Apple for the iPad Pro; How to make the Widget of batteries displayed on the notification Center 'today '?

    I have associated my pencil to Apple for the iPad Pro; But how to make the Widget of batteries displayed on the notification Center 'today '?

    See if it works. Scroll to the bottom of the list in the display today. Tap on edit. Press on the + sign next to battery.

  • How to make the snow fall go far in the background that I've recently added a newsletter on your part?

    How to make the snow fall go far in the background that I've recently added a newsletter of mozilla to? It appears on things, I feel.

    I can't talk about it. What is an extension?

    You can disable or remove unwanted page extensions modules. Either:

    • CTRL + SHIFT + a
    • Firefox orange (or the Tools menu) button > Add ons

    In the left column, click Extensions. If you don't it spot, perhaps in the appearance section?

  • How to make the text bigger in youtube! Cubs in youtube!

    I made the largest text where google search arrives! But when I go on youtube the text is much tinier and I 65 to cataract and I can't read the text at right! How to make the text bigger in youtube? Thank you very much! I tried everything, but nothing changes the size!

    When you view this page hit {Ctrl + 0} < is a zero number -to reset the zoom level for this area.

    https://support.Mozilla.com/en-us/KB/page+zoom

    If you move the scroll wheel, and are now the CTRL key, you can change the zoom level of the page that is viewed - both in & out.

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

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

    Have you checked the home page to make sure that if is not the vertical bar (|) symbols?

    See the following for a few suggestions:

  • How to make the text darker or bolder

    How to make the text darker or bolder in safari

    shutterbox-

    I'm with you.  Cataract surgery, it will take longer, and the thin, plugged in my humble OPINION, typeface they chose is really for less than 40 eyes.

    The same "BOLD" of the police system capacity would be so appreciated.

    There are 3rd party apps that can change system fonts, and I saw messages claiming success, but I'm a purist to try.

    Small fonts (to us) make it very painful to be here.  I just hope they realize that our needs must be met, as well.

  • S3000-514: how to make the secondary battery to unload everything first?

    Hello world!
    After I ve managed to charge my secondary battery on my laptop (see my previous announcement), I'm now getting another "strange" problem
    With my two batteries in and on the battery the first battery to discharge is the main battery - and not high school!
    This leads to a problem: when I want to change the secondary battery with my combo player, I'm not always have enough power in my battery.
    I have found how to make the battery discharging first of haven´t.
    Can anyone help?

    Hello

    Unfortunately, it is not for me and as much as I know it can not be changed. Probably the electronic power supply is configured to run on this path. Have you tried to remove the main battery and work by simply using secondary? What happens in this case?

  • How to change the location of the @ how to make the Euro symbol and where is 'hash '?

    I am a proud new owner Portege M300. Now all I need? knowledge is:

    -keyboard looks liks the sign @ is above the 2. In fact, it's above the apostrophe, where the quote is true. I want to have the @ sign overcoming the 2 because that's what I'm used to =. How I change these autour?

    -How to make the Euro sign (as £ and $)?

    -Why is£ 3 rather than the 'hash' sign that is posted above? How to make the sign of 'hash '?

    Hello

    Before you can perform any discussion can you please tell me in which country is your laptop bought and what specific keyboard of the country to unity? Each cell has a specific keyboard of the country.

Maybe you are looking for