Multiple conditin on a single column in a single query

i want to select data from the table using diff conditions on a single column
for eg:
i need emp details like whose having empno as 5-15,19-45,50-89 ..etc this how can i give a condition in a single query
we can use in or between for 2 or 3 conditions but i have plenty off like this

Hi,
848525 wrote:
i want to select data from the table using diff conditions on a single column
for eg:
i need emp details like whose having empno as 5-15,19-45,50-89 ..etc this how can i give a condition in a single query
we can use in or between for 2 or 3 conditions but i have plenty off like thisYou can use OR for any number of conditions; it works the same for 4 or more.
You could also put the ranges into a table (or a sub-query, as shown below) and join:
WITH     empno_ranges     AS
     SELECT     3000 AS low_val, 5000 AS high_val  FROM dual  UNION ALL
     SELECT     7000,           7499               FROM dual  UNION ALL
     SELECT     7500,           7599               FROM dual  UNION ALL
     SELECT     7800,           7899               FROM dual
SELECT       r.*
,       COUNT (e.empno)     AS emp_cnt
FROM            empno_ranges     r
LEFT OUTER JOIN     scott.emp     e  ON  e.empno  BETWEEN r.low_val
                                             AND     r.high_val
GROUP BY  r.low_val, r.high_val
ORDER BY  r.low_val
;Output:
LOW_VAL   HIGH_VAL    EMP_CNT
   3000       5000          0
   7000       7499          2
   7500       7599          2
   7800       7899          3

Similar Messages

  • Retrieve multiple row single column output as single string

    hii
    I have query like "select country_name from country_master where <condition>".
    This query results in multiple rows. I want those multiple rows as a string like "country1, country2, contry3".
    I know i can write a function/cursor to achieve that but want to know if we have a way to get that within the query itself.
    Thanks

    In 10g...
    SQL> select dname from dept;
    DNAME
    ACCOUNTING
    RESEARCH
    SALES
    OPERATIONS
    IT SUPPORT
    SQL> ed
    Wrote file afiedt.buf
      1  select ltrim(sys_connect_by_path(dname,','),',') as depts
      2  from (select dname, row_number() over (order by deptno) rn from dept)
      3  where connect_by_isleaf = 1
      4  connect by rn = prior rn + 1
      5* start with rn = 1
    SQL> /
    DEPTS
    ACCOUNTING,RESEARCH,SALES,OPERATIONS,IT SUPPORTIn 11g, you can use the LISTAGG analytical function.

  • How to display two or more links in a single column

    Hi,
    Is there a way to display two links in a single column in a sql query report . I am able to specify one but I am not able to add links to the same column . I want to take the same column id and redirect the user to different pages based on the values selected .
    Thanks

    There is no way to this declaratively that I know of. Some alternatives...
    1. Put the conditional branching logic in the report SQL itself. e.g. case when ... then '< a href=..' else '< a href=...' end and make sure the column display type is Standard Report column
    2. Have the declarative column link go to a dummy/intermediate page and setup On Load: Before-Header branches on that page to redirect to the desired page based on the item value(s) passed in to the intermediate page.

  • How To Concatenate Column Values from Multiple Rows into a Single Column?

    How do I create a SQL query that will concatenate column values from multiple rows into a single column?
    Last First Code
    Lesand Danny 1
    Lesand Danny 2
    Lesand Danny 3
    Benedi Eric 7
    Benedi Eric 14
    Result should look like:
    Last First Codes
    Lesand Danny 1,2,3
    Benedi Eric 7,14
    Thanks,
    David Johnson

    Starting with Oracle 9i
    select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
    from
    (select last, first, code, row_number() over(partition by last, first order by code) rn
    from a)
    connect by last = prior last and first = prior first and prior rn = rn -1
    start with rn = 1
    group by last, first
    LAST       FIRST      CODES                                                                                                                                                                                                  
    Lesand         Danny          1,2,3
    Benedi         Eric           7,14Regards
    Dmytro

  • Multiple Hotspots in a ALV Grid single column

    Hi Experts,
    My ALV Grid report output looks like below....
    If you observe below output, column 3 has multiple documents each one separated by ' ; '. Now, I would like to assign hotspot on each documents like DOC1, DOC2, DOC3, etc.
    Heading#:          COL1 | COL2 | COL3 |
    Records1:              1      |  xxxxx  | _DOC1_ ; DOC2 ; *DOC3*
    Records2:              2      |  xxxxx  | _DOC1_ ; DOC5 ;
    I know, we can assign hotspot for entire column. but my requirement is multiple hot spots in a single column.
    Please help me on this?
    Thanks in Advance
    Raghu

    As I mentioned earlier,
    My ALV Grid report output looks like below....
    Heading#: FIELD1 | FIELD2 | FIELD3 |
    Records1: 1 | xxxxx | DOC1 ; DOC2 ; DOC3
    Records2: 2 | xxxxx | DOC1 ; DOC5 ;
    If you observe above output, field 3 has multiple documents each one separated by ' ; '.
    When I click on DOC1, it supposed to display related picture on the POP-Up Screen. Similarly when I click on DOC2, it supposed to display that document picture on POP-up screen.
    Before going to do this, first I need to assign hotspots on each documents like DOC1, DOC2, DOC3, etc.
    Please help me.

  • Can I get multiple sums in a single column based on a "code" I place.

    After importing a file of check/debit card activity from my bank, can I 'code' the line items based on tax categories ie Utilities, Medical expenses, Auto expenses, etc. and then get sums for each based on that code I placed in a single column? That would mean multiple sums in a single column based on the code used for each tax related expense. For instance, I would put UT in the column for utilities expenses and MED in the same column if it were a medical expense. I would then want the sum for all items in that column for each item code. Is this possible or do I need to use a different approach to get this information.

    My guess is that the SUMIF function may be your friend.
    It's well described in the *iWork Formulas and Functions User Guid*e which every user may download from the Help menu.
    Yvan KOENIG (VALLAURIS, France) samedi 2 janvier 2010 21:56:39

  • Concatenate multiple row values into single column value

    Hello,
    Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
    In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
    SELECT a.application_id, a.membership_number,
    r.reason_text AS denial_reason,
    a.appl_receipt_date AS application_receipt_date,
    a.plan_request_1 AS application_plan_code,
    a.adjudication_date AS application_denial_date
    FROM application a, PLAN p, application_reason ar, reason r
    WHERE a.plan_request_1 = p.plan_cd
    AND a.application_id = ar.application_id
    AND ar.reason_id = r.reason_id
    AND a.adjudication_cd = 'D'
    AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
    AND p.plan_type_id = 12 and a.application_id = :appId
    ORDER BY application_id
    Any help is greatly appreciated.
    Thanks,
    -Christine

    found the following
    SELECT deptno,
           LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
           KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT deptno,
                   ename,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
            FROM   emp)
    GROUP BY deptno
    CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
    START WITH curr = 1;
        DEPTNO EMPLOYEES
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
    3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

  • How to calculate the individual sums of multiple columns in a single query

    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    Thanks

    user13667036 wrote:
    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    ThanksLooks like you want a simple group by.
    select
              yr
         ,      mnth
         ,      region
         ,     sum(handled_package)
         ,     sum(expected_missing_package)
         ,     sum(actual_missing_package)
    from test
    group by
         yr, mnth, region
    order by      
         yr, mnth, region;I wouldn't recommend storing your data for year / month in 2 columns like that unless you have a really good reason. I would store it as a date column and add a check constraint to ensure that the date is always the first of the month, then format it out as you wish to the client.
    CREATE TABLE test
         year_month                              date,
        Region                     VARCHAR2(50),
        CITY                       VARCHAR2(50),             
        Handled_Package            NUMBER,       
        Expected_Missing_Package   NUMBER,   
        Actual_Missing_Package     NUMBER
    alter table test add constraint firs_of_month check (year_month = trunc(year_month, 'mm'));
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-12', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
    ERROR at line 1:
    ORA-02290: check constraint (TUBBY.FIRS_OF_MONTH) violated
    Elapsed: 00:00:00.03
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-01', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    1 row created.
    Elapsed: 00:00:00.01
    ME_XE?select
      2        to_char(year_month, 'fmYYYY')    as year
      3     ,  to_char(year_month, 'fmMonth')   as month
      4     ,  Region
      5     ,  CITY
      6     ,  Handled_Package
      7     ,  Expected_Missing_Package
      8     ,  Actual_Missing_Package
      9  from test;
    YEAR         MONTH                REGION                         CITY                    HANDLED_PACKAGE EXPECTED_MISSING_PACKAGE ACTUAL_MISSING_PACKAGE
    2012         November             Western                        San Fransisco                       200                       10                      5
    1 row selected.
    Elapsed: 00:00:00.01
    ME_XE?Then you have nice a nice and easy validation that ensures you data integrity.
    Cheers,

  • Using sql load insert multiple fields data into a single column in database

    Hi ,
    I have my log file in sun OS box something like this
    =======
    (07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
    (07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
    (07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
    =============
    I am trying to insert the data into oracle data base as follows.
    =============================
    column1 : (07/29/2009 00:02:24.467)
    column2 : 367518
    column3 : (07/29/2009 00:02:26.214)
    column4 : 949384011
    ===========================
    Can anyone help me with the control file format?
    someone suggested me the code below.
    ==========
    LOAD DATA
    INFILE 'D:\work\load.txt'
    INTO TABLE sample
    (col1 POSITION(02:24) char,
    col2 POSITION(27:32) INTEGER EXTERNAL,
    col3 POSITION(35:57) CHAR,
    col4 POSITION(60:68) INTEGER EXTERNAL
    ===========
    but this works only for the fixed length data? Please help

    user11744904 wrote:
    Hi ,
    I have my log file in sun OS box something like this
    =======
    (07/29/2009 00:02:24.467) 367518 (07/29/2009 00:02:26.214) 949384011
    (07/29/2009 00:02:26.236) 3675 (07/29/2009 00:02:28.207) 949395117
    (07/29/2009 00:02:28.240) 337710 (07/29/2009 00:02:30.621) 949400864
    =============
    I am trying to insert the data into oracle data base as follows.
    =============================
    column1 : (07/29/2009 00:02:24.467)
    column2 : 367518
    column3 : (07/29/2009 00:02:26.214)
    column4 : 949384011
    ===========================
    Can anyone help me with the control file format?
    someone suggested me the code below.
    ==========
    LOAD DATA
    INFILE 'D:\work\load.txt'
    INTO TABLE sample
    (col1 POSITION(02:24) char,
    col2 POSITION(27:32) INTEGER EXTERNAL,
    col3 POSITION(35:57) CHAR,
    col4 POSITION(60:68) INTEGER EXTERNAL
    ===========
    but this works only for the fixed length data? Please helpIs the requirement to load all data in a single column or multiple columns? The thread subject and body are conflicting.

  • Displaying data from multiple columns into a single line graph

    Post Author: hollowmatrix
    CA Forum: WebIntelligence Reporting
    Hey,I have an issue with the WEBI reporting.I have a data source that has multiple columns say ( month1, month2, month3, month4,.....month 12, month 13, ....month24) with the sales data for each month.Now say I call the month 1 to month 12 as "current year", and call month 13 - month 24 as "previous year".I want to put a prompt in the report which allows  me to select between "current year" and "previous year".Based on the prompt value we get a graph of the sales vs month ....as in if we select  "current year", then we get a graph of the sales Vs time( remember that the sales data for each month is in a different column.)and if we select  "previous year" then we get a graph of the sales Vs time for previous year..( sales vs time for Month 13, month 14, month 15....month 24).I am not able to pull data from multiple columns into a single object that I can use to populate the graphs.Any help on the same will be appreciated .   

    Hi,
    <p>
    please click
    here (asktom) and look for the words "how about the other way round"
    </p>

  • How to insert from one table to another (multiple columns to single column)

    I want to insert data from table1 into table2 and the data looks in 3 columns as below
    Table1     
    RepNm ObjNm DbNm
    123     abc def
    456     def xyz
    789     123 456
    and the data in table2 should be display as
    Table 2
    ObjNm
    123
    456
    789
    abc
    def
    xyz
    the dupes should get eliminated and only the distinct values should be inserted into a single column in table2 from multiple columns in table1

    How do you want to handle nulls? If there is a null in any value of a column, do you want to insert it?
    Then,
    WITH T
         AS (SELECT LEVEL colnum
               FROM DUAL
             CONNECT BY LEVEL <= 3)
    SELECT DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm) as ObjNm
      FROM table1, T;if you dont want to insert nulls then,
    WITH T
         AS (SELECT LEVEL colnum
               FROM DUAL
             CONNECT BY LEVEL <= 3)
    SELECT DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm) AS ObjNm
      FROM table1, T
    WHERE DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm) = DECODE (colnum,  1, RepNm,  2, ObjNm,  3, DbNm)G.

  • How to import multiple Excel/CSV columns into a single Sharepoint metadata choice column?

    Consider: I work for an organization that has eight service territories.  We have a series of procedural documents that can apply to from one to eight territories. We are moving this data over to sharepoint, and I'd like to add territory
    data as metadata. Unfortunately, with our current knowledge management system, the best we can get is 8 separate fields flagged as yes/no.
    is1 is2 is3 is4 is5 is6 is7 is8
    1   0  
    1   1   0  
    0   0  
    0
    0   0  
    0   1   1  
    0   0  
    0
    0   0  
    0   0   0  
    0   1  
    0
    I would like to be able to import this data into a SINGLE sharepoint metadata column as Choice/checkboxes/allow Multiple values. Is there a way to do this? We're using Foundations 2010, and our area does not have access to
    development tools (including SPD).

    Thanks for the reply. We have eight individual Columns in the Excel File, and when we do the import to Sharepoint, yes we get eight individual metadata columns.
    I would LIKE to be able to import the eight columns into ONE column in Sharepoint.
    Consider three documents.
    Doc1 is information applicable to Territories 1,3 & 4.
    Doc2 is information applicable to Territories 4 & 5.
    Doc3 is information applicable to Territory 7.
          is1 is2 is3 is4 is5 is6 is7 is8
    doc1   1   0  
    1   1  
    0   0   0  
    0
    doc2   0   0  
    0   1  
    1   0   0  
    0
    doc3   0   0  
    0   0  
    0   0   1  
    0
    This metadata would import to a SINGLE column in SharePoint called IsTerritory, which is defined as a Checkbox (multiple values) Choice Field, limited to the values 1-8.
    Doc1 would have checkboxes 1,3, & 4 checked, Doc2 would have checkboxes 4 & 5 checked, and Doc 3 would only have checkbox 3 checked.
    Does that make a little more sense? I'm having problems validating my account, so I can't upload screenshots yet...
    Thanks in advance for your reply.

  • Performance of update query for single column vs multiple column

    Hi All,
    I could not find any answer for this, does it ever matter in terms of performance updating single column versus multiple column in a single update query.
    For eg. table consisting of 15 columns, what would be the difference in performance when one column is update in the single query against another update query where 15 columns are updated.
    Please do keep in mind my table columns in actually could be around 150+.
    Thanks for any information provided.

    If updated columns aren´t on where clause , then the only impact of 15 columns will be a increase on redo generation, and a possible chainning row.
    So since the redo is one of the things that have a large impact, the answer is yes.
    The performance will be slower.
    Regards
    Helio Dias.
    http://heliodias.com
    OCE SQL, OCP 9i

  • Merge statement - update multiple columns from a single sub-select

    Is it possible to write in 10gR2, a MERGE statement, with UPDATE for multiple columns from a single sub_select?
    like this:
    MERGE INTO tableA
    using ( select * from temp) tmp
    on( tableA. col1 = tmp.col1)
    when matched then
    update set  ( tableA.col5,
                       tableA.col6,
                       tableA.col7) = ( select sum(col2), sum(col3), sum(col5)
                                                                                 from tableX
                                                                                where tableX.col1 = tableA.col1...)

    Hi,
    The USING clause is not a sub-query, so it can't reference columns from tables that are not in it.
    Include tableA in the USING clause if you really need to refer to it there. (It's not obvious that you do.)
    As always, it helps if you post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data (In the case of a DML statement, such as MERGE, this will be the state of the tables when everything is finished.)
    (4) Your best attempt so far (formatted)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, tables in scott schema, or views in the data dictionary), then you can omit (2).
    Formatted tabular output is okay for (3).

  • Converting multiple column in single column

    Hi All,
    I need to create a table with single column by using select statement with multiple columns
    For Ex- i have 1 row with 10 columns (may be more than 10) like
    'A','B','C','D','E','F','G','H',I','J'
    i written sql like
    select 'A','B','C','D','E','F','G','H','I','J' from dual
    result is - 'A','B','C','D','E','F','G','H','I','J' with 10 columns
    Now i need output lik this using SQL
    Text
    'A'
    'B'
    'C'
    'D'
    'E'
    'F'
    'G'
    'H'
    'I'
    'J'
    Please help me to sort out this problem. Your help would highly appropriated.
    Regards
    Raju
    Edited by: 888667 on Apr 8, 2013 10:54 PM
    Edited by: 888667 on Apr 8, 2013 10:56 PM

    Welcome to the forum!!! You can convert column to row like this
    SQL>with my_table
      2  as
      3  (
      4  select 'A' col1,'B' col2,'C' col3,'D' col4,'E' col5,'F' col6,'G' col7,'H' col8,'I' col9,'J' col10
      5    from dual
      6  )
      7  select decode(no , 1, col1, 2, col2, 3, col3, 4, col4, 5, col5, 6, col6, 7, col7, 8, col8, 9, col9, 10, col10) col
      8    from my_table
      9    cross join (select level no from dual connect by level <= 10)
    10  /
    C
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    10 rows selected.
    SQL> To ask question in a better way please read {message:id=9360002} from FAQ

Maybe you are looking for