Combine the 2 columns in a single table

Hello people.
I have the following query:

SELECT col1, COUNT (*)
FROM table1
WHERE ID = 10
AND col1 IN (' a ',' B', 'C', d ', 'E', 'F', 'G', 'H', 'I')
GROUP OF CUBE (col1);

which generates:

col1 COUNT (*)
--------------- -----------------------
A 7677
B 25852
A s
D 176
E 10
F 127
G 508
H 6
34357

Now I have the same query with an additional condition (NR > 50):

SELECT col1, COUNT (*)
FROM table1
WHERE ID = 10
AND NR > 50
AND col1 IN (' a ',' B', 'C', d ', 'E', 'F', 'G', 'H', 'I')
GROUP OF CUBE (col1);

Which generates:

col1 COUNT (*)
--------------- -----------------------
A 4567
B 14544
A s
D 16
E 7
F 105
300 G
F |
19542

I need to combine these 2 requests so I can get a report like this:

col1 COUNT (*) COUNT (*)
--------------- ----------------------- -----------------------
A 4567 7677
14544 25852 B
1 1 C
D 16 176
7 10 E
F 105 127
G 300 508
2 6 H
19542 34357

I tried something like:

SELECT b.col1, COUNT (b.ID).
(SELECT COUNT (d.ID)
OF table1 d
WHERE d.ID = 10
AND d.NR > 50
AND d.col1 IN (' a ',' B', 'C', d ', 'E', 'F', 'G', 'H', 'I')
CUBE GROUP (d.col))
Table 1 b
WHERE b.ID = 10
AND b.col1 IN (' a ',' B', 'C', d ', 'E', 'F', 'G', 'H', 'I')
AND b.ID = d.ID?
GROUP OF CUBE (b.VEHICLE_KIND_CL);

but I can't get it to work.
Any help will be much appreciated.

Try:

SELECT col1, COUNT(*) count_all, count(CASE WHEN nr > 50 THEN 1 END) count_over_fifty
FROM   table1
WHERE  ID=10
AND    col1 IN ('A','B','C','D','E','F','G','H','I')
GROUP BY CUBE(col1);

Tags: Database

Similar Questions

  • Combine the three columns into a single

    Hello

    We have a hierarchy of dimension organization at three levels: company-> Group-> business units operating... each with a total of actual AMAURY. (Business Units drive business groups and business groups roll in society)

    I want to display the data for the amounts of the CDA in a simple table report but I need to have the name of the entity (company, group operating Business Unit) doesn't appear in the same column, only not as a hierarchy.

    Example:

    Company $1-6500
    Working Group 1-2 $500
    Business Unit 1-$1000
    Business Unit 2-$1500
    Group 2-$4000
    Business Unit 3-$3000
    Business Unit 4-$1000

    Is this possible?

    TIA,
    Ash.

    A possible solution: you have to do four-speed with two columns.

    One for the company
    One for the Business unit
    One group of operation

    And the other to a Union of the first three reports.
    And you need to add a column to sort (hierarchy pesudo) If you want to see the values in the correct order.

  • Combine the two columns of text

    I have two columns of text (say that name is a column and the name is the other)

    I would like to combine the two columns for the text of these two columns are in a column. (First name and last name in the same column)

    Is this possible? If so is there a tutorial somewhere?

    Hi Danielle,

    The & (concatenation operator) is your friend.

    Formula in D2 (fill down)

    "B2 &" "& C2.

    & joins elements into a single string.

    "" inserts a space.

    Kind regards

    Ian.

  • How to find the same column name in different tables in the same schema

    Hello

    I find the 'ename' column name in different tables in the same schema.

    Thank you
    Nr

    Hello

    Try this query

    Select column_name, table_name from user_tab_columns where column_name = 'ENAME ';

    Award points and end the debate, if your question is answered or mark if she was...

    Kind regards

    Lacouture.

  • Combine the two columns of the table

    SELECT providerid, Sum OF appdev.usercounts
    WHERE the counttime BETWEEN SYSDATE - 30/1440 AND SYSDATE-15/1440 GROUP BY ORDER BY providerid providerid

    697 W
    U 813
    T 143
    S 2

    SELECT providerid, Sum OF appdev.usercounts
    WHERE the counttime BETWEEN - 30/1440 AND (SYSDATE-1) - 15/1440 (SYSDATE-1) GROUP BY ORDER BY providerid providerid;

    450 W
    U 571
    T 80
    S 2

    I want output like

    W 697 450
    U 813 571
    143 80 T
    2 2 S
    Help, please

    Thank you
    Praveen

    'COUNT', which is the actual column name? It could become very confusing.

    Not tested for obvious reasons, but it should be close:

    SELECT providerid
         , sum(
             case when counttime between sysdate - 30/1440 and sysdate - 15/1440 then count end
           ) as cnt1
         , sum(
             case when counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 then count end
           ) as cnt2
    FROM appdev.usercounts
    WHERE ( counttime between sysdate - 30/1440 and sysdate - 15/1440 )
       OR ( counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 )
    GROUP BY providerid
    ORDER BY providerid
    ;
    
  • Combine the two columns?

    HI, the problem is this, I have two columns: start_date and end_date

    Invite a: start date (for example 08/08/2008)
    Invite two: End Date (for ouvertede 30/04/2009)

    so these are two different columns, do you know how get all the data between these two dates.
    If I use the "between the function" I can't get the dates between the same column,
    The start date
    The start date

    but I need the end date...

    I really appriciate to help

    Thank you

    Hello

    Something like:

    SELECT *
    FROM   
    WHERE  start_date BETWEEN TO_DATE('08/08/2008', 'mm/dd/yyyy') AND TO_DATE('04/30/2009', 'mm/dd/yyyy')
    OR     end_date BETWEEN TO_DATE('08/08/2008', 'mm/dd/yyyy') AND TO_DATE('04/30/2009', 'mm/dd/yyyy');
    

    Kind regards

  • How can I combine the 2 vertical cells in a table 2 ranks, while retaining his other 4 columns NONmerged?

    I use Dreamweaver CS5 and wonder if there is a way to merge 2 vertical cells centralized in a table of 2 oars, while cells of his other 4 columns (2 on each side) NONmerged.   It is possible, please?   I go to:

    MODIFY-> TABLE

    but the function "MERGE CELLS" which seems it is dark, while the other options are, however, ready to be selected.   I've experimented with trying to select the two cells to merge, but that did not work or the other.   This could be a bug in the software?   Or could I do something naively?

    Happy 2012 at all :-)

    DreamWeaverBeliever wrote:

    I use Dreamweaver CS5 and wonder if there is a way to merge 2 vertical cells centralized in a table of 2 oars, while keeping other cells 4 columns (2 on each side) NONmerged.   It is possible, please?   I'll EDIT--> TABLE, but the function "MERGE CELLS" which seems it is dark, while the other options are, however, ready to be selected.   I've experimented with trying to select the two cells to merge, but that did not work or the other.   This could be a bug in the software?   Or could I do something naively?

    Happy 2012 at all :-)

    Is this possible?  Yes it is possible.  May be a bug in the software?  No, it's not a bug in the software.

    To merge cells, select the cells that contiguous with your mouse.  Click on a cell and with the left mouse button pressed, drag it to other cells that are to the right and below.

    You can now use merge cells and it should work.

    The alternative is to work in code view and change the code to look like this:

     

    I hope this helps.

  • The combination of two columns in a single

    Hi guys,.

    Is it possible for a query to combine two columns into one? For example, lets say I have the following query:

    SELECT ID, FIRST_NAME, LAST_NAME
    EMPLOYEES

    I want the output to have two columns: one that contains the ID and the other containing name followed by a space followed by LAST_NAME. I know how to do this outside the query using coldfusion, but it save me a lot of work if there is some way that the query could do for me.

    Yes but the operand of concatenation varies somewhat from a database
    management system to the other.

    In Oracle, it would look this IIRC.

    SELECT ID, FIRST_NAME. ' ' || LAST_NAME AS FULL_NAME
    EMPLOYEES

  • How can I find the top row of a single table, split among several images in each image.

    Hi all.

    Thanks in advance.

    You can browse all the cells in a row column * and ask the first insertion of a text on his cell point user.user parentTextFrames [0].

    If the ID value has changed, the cell is in a different text frame. As well as its line.

    CC-2015, it might be a little different, because we have a new type of cell: CellTypeEnum.GRAPHIC_TYPE_CELL (not insertionPoints pave the way).

    You can also:

    Reproduce all text blocks in history, in that the table is sitting and control for unique tables in duplicates.

    Uwe

    * edit

  • Resize the VARCHAR2 column on a large table

    Hello

    I need to resize a column VARCHAR2 with a large table (several hundred million lines).
    The column will be reduced from VARCHAR2 (40) to VARCHAR2 (50).
    Please check if someone has idea, will be this column resizing take a lot of time or a lot of resources that the table is highly accessible.
    Thank you.

    Kind regards
    Tarman.

    This should be an update of the dictionary: so it should very quickly because the existing data will not be changed.

    See http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1542606219593 #1956714100346356542.

  • How to combine the two queries into a single

    Hi gurus,

    SQL > select * from v version $;

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Release 10.2.0.4.0 - Production 64-bit

    PL/SQL Release 10.2.0.4.0 - Production

    CORE 10.2.0.4.0 Production

    AMT for Linux: release 10.2.0.4.0 - Production

    NLSRTL Version 10.2.0.4.0 - Production

    SQL >

    I have following two queries. How can I convert these two queries into one with the same result?

    1ST QUARTER

    SELECT id, $vdate, SupplierName, venddate, vid

    THE SELLER

    WHERE processid = 32

    AND venddate is null

    AND vid to (select vid from view_vid where type = 'PDX')

    AND (id, $vdate) not in (select id, $vdate from vkfl_is where task_id = 55)

    AND (id, $vdate) in (select id, vidate from market_data where marketed_date is null)

    AND id not in (select id from location)

    Q2

    SELECT id, $vdate, SupplierName, venddate, vid

    THE SELLER

    WHERE processid = 20

    AND venddate is null

    AND vid to (select vid from view_vid where type = 'PBX')

    AND (id, $vdate) not in (select id, $vdate from vkfl_is where task_id = 40)

    AND (id, $vdate) in (select id, vidate from market_data where region_date is null)

    AND id not in (select id from location)

    I can the UNION queries these two, but is there some way I can write a single query that gives me the same result as above two queries?

    Any help would be much appreciated

    Thanks in advance

    Sorry, it lack

    SELECT id, $vdate, SupplierName, venddate, vid

    THE SELLER

    ProcessID WHERE in (32.20)

    AND venddate is null

    AND vid to (select vid from view_vid where type = case when processid = 32

    then "PDX".

    else "PBX".

    end)

    AND (id, $vdate) not in (select id, $vdate from vkfl_is where task_id = case when processid = 32

    then 55

    40 else

    end)

    AND (id, $vdate) in (select id, vidate from market_data cases where processid = 32)

    then marketed_date

    of other region_date

    end to the null value

    )

    AND id not in (select id from location)

    Concerning

    Etbin

  • can update us two columns from a single table at a time

    Hi all

    We can write an update on towing both columns

    as set of update < table name > < Column1 > = 'xx' and < colmn2 > = "uu" where < Column3 > 'rrr '.


    Thank you

    You can.

    Like this

     update  set ='xx' ,='uu' where 'rrr'
    
    

    Concerning
    Sankar MN

  • How to insert the 20 records in a single table

    Hi all,
    I want to insert documents 20 only in a table, but suppose I want to enter the folder 21 it will be not inserted.
    Suppose that to delete a record and then insert, it will insert.
    but always count (*) is not greater than 20.
    is there any solution for this
    Please help me

    Create a trigger Before Insert database on the table to keep the count = 20 in the table. If it exceeds, raise the exception and cancel the insert operation.

  • Fusion of single table

    Hi all

    I am using the command merge onto a single table. I want to check some values in the table, if they already exist I just update, thing that I want to insert.

    For this I use the following code:



    MERGE INTO my_table OLD_VAL
    NEW_VAL in ASSISTANCE from (SELECT L_field1, L_field2, L_field3, DOUBLE L_field4)
    WE (OLD_VAL.field1 = NEW_VAL. L_field1
    AND OLD_VAL.field2 = NEW_VAL. L_field2
    AND OLD_VAL.field3 = NEW_VAL. L_field3
    )
    WHEN MATCHED THEN
    UPDATE SET OLD_VAL.field4 = NEW_VAL. L_field4
    WHEN NOT MATCHED THEN
    INSERT (Field1, Field2, field3, field4, sphere5)
    VALUES (NEW_VAL. L_field1, NEW_VAL. L_field2, NEW_VAL. L_field3, NEW_VAL. L_field4, SYSDATE);

    Fields starting with L_ here is my local variables inside my procedure.

    It is giving error as ORA-00904: "NEW_VAL. "" L_field3 ": invalid identifier

    Thank you all.

    SELECT L_field1, L_field2, L_field3, DOUBLE L_field4

    1. you r select all values here?
    2. try to give alias for all columns

  • question of Style CSS for the adftable: column 10g

    I'm being aligned left the author column in this adf:table, but I can't make it work. The styleClass does not seem to work for her. I looked in the count, but because the styleClass is not applied, I can't work for this single column. Any suggestions?

    Thank you

    Andy
    <af:table rows="15"
                 banding="row" 
                 bandingInterval="1"
                 var="book"
                 id="currentImmunizationsTable"
                 width="900" 
                 value="#{backingbean.books}"
                 rendered="#{! empty backingbean.books}"
                 immediate="true">
      <af:column sortable="true"
                       sortProperty="author"
                       headerText="Author"
                       id="authorColumn"
                       formatType="icon"
                       gridVisible="true"
                       styleClass="column">
        <af:outputText value="#{book.author}"
                               id="authorText">
        </af:outputText>
      </af:column>
      ...
    </af:table>
    Published by: anotherhale on June 21, 2010 14:04

    Hello

    You can post your markup code all of the af:table? and if possible also expose the screenshot of disabled grid lines? This skin do you use? I don't remember any problem with af table grid lines

    Kind regards

    Branislav

  • Maybe you are looking for