Query for getting combination of data

hi all,
i am using db10g.
i have a table of fields a_company,a_code,a_name,a_port,a_t_port,a_rate,a_volume
i have a records like
MM,AA,A-NAME,EFG,EFGH,100,20
MM,AA,A-NAME,EFG,EFGH,200,10
MM,BB,B-NAME,HIJ,HIJK,100,20
MM,BB,B-NAME,HIJ,HIJK,200,30
MM,CC,C-NAME,DEF,DEFG,500,20i have to select all columns but the fields if below below combination repeates(having more than 1 combination)
a_company,a_code,a_port,a_t_port
how can form a query?
in other words i am expecting the result like below among above said input.
MM,AA,A-NAME,EFG,EFGH,100,20
MM,AA,A-NAME,EFG,EFGH,200,10
MM,BB,B-NAME,HIJ,HIJK,100,20
MM,BB,B-NAME,HIJ,HIJK,200,30Thanks..

With only one table scan:
SQL> create table a_table (a_company,a_code,a_name,a_port,a_t_port,a_rate,a_volume)
  2  as
  3  select 'MM','AA','A-NAME','EFG','EFGH',100,20 from dual union all
  4  select 'MM','AA','A-NAME','EFG','EFGH',200,10 from dual union all
  5  select 'MM','BB','B-NAME','HIJ','HIJK',100,20 from dual union all
  6  select 'MM','BB','B-NAME','HIJ','HIJK',200,30 from dual union all
  7  select 'MM','CC','C-NAME','DEF','DEFG',500,20 from dual
  8  /
Table created.
SQL> exec dbms_stats.gather_table_stats(user,'a_table')
PL/SQL procedure successfully completed.
SQL> set autotrace on explain
SQL> select a_company
  2       , a_code
  3       , a_name
  4       , a_port
  5       , a_t_port
  6       , a_rate
  7       , a_volume
  8    from ( select a.a_company
  9                , a.a_code
10                , a.a_name
11                , a.a_port
12                , a.a_t_port
13                , a.a_rate
14                , a.a_volume
15                , count(*) over (partition by a_company,a_code,a_port,a_t_port) cnt
16             from a_table a
17         )
18   where cnt > 1
19  /
A_ A_ A_NAME A_P A_T_     A_RATE   A_VOLUME
MM AA A-NAME EFG EFGH        100         20
MM AA A-NAME EFG EFGH        200         10
MM BB B-NAME HIJ HIJK        100         20
MM BB B-NAME HIJ HIJK        200         30
4 rows selected.
Execution Plan
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=5 Bytes=330)
   1    0   VIEW (Cost=4 Card=5 Bytes=330)
   2    1     WINDOW (SORT) (Cost=4 Card=5 Bytes=140)
   3    2       TABLE ACCESS (FULL) OF 'A_TABLE' (Cost=2 Card=5 Bytes=140)Regards,
Rob.

Similar Messages

  • Query for getting all function and procedure inside the packages

    hi All
    Please provide me Query for getting all function and procedure inside the packages
    thanks

    As Todd said, you can use user_arguments data dictionary or you can join user_objects and user_procedures like below to get the name of the packaged function and procedure names.
    If you are looking for the packaged procedures and functions source then use user_source data dictionary
    select a.object_name,a.procedure_name from user_procedures a,
                  user_objects b
    where a.object_name is not null
    and a.procedure_name is not null
    and b.object_type='PACKAGE'        
    and a.object_name=b.object_name

  • For getting the back date

    dear all,
    i want to display 10 days back date from today date
    like sysdate - 20 days back date.
    please send me the query for getting the date of back
    Thanks in advance

    Hi do you want all the dates from the back date to sysdate or only the particular back date
    SQL> select sysdate from dual;
    SYSDATE
    22-JUN-09
    SQL> select sysdate-10 from dual;
    SYSDATE-1
    12-JUN-09or if you want all the back dates starting from one particular then
    SQL> select sysdate-10+level from dual
      2  connect by level<=10;
    SYSDATE-1
    13-JUN-09
    14-JUN-09
    15-JUN-09
    16-JUN-09
    17-JUN-09
    18-JUN-09
    19-JUN-09
    20-JUN-09
    21-JUN-09
    22-JUN-09
    10 rows selected.Edited by: oracle_for_dude on Jun 22, 2009 12:11 PM

  • What are the prerequisite for getting MTTR / MTBR data.

    Dear SAP Experts,
    I want to know what are the prerequisite for getting MTTR / MTBR data.
    Regards
    ERP Tech

    Pre-requisites are:
    Maintain Start date in Equipment / Functional location master
    Maintain the Malfunction Start date & time, Malfunction End Date & time in Notification
    Maintain the Breakdown tick mark in notification
    Maintain update group (stats) in Notification type configuration (IMG - Plant Maintenance & Customer Service - Maintenance & Service Processing - Maintenance & Service Notifications - Notification types - Define Notification types)

  • Can I get a query to get the output data like 4th column instead of 3rd col

    Can I get a query to get the output data like 4th column instead of 3rd column ?
    SQL&gt; select emp.deptno, empno, rownum from emp, dept where emp.deptno=dept.deptno;
    DEPTNO EMPNO ROWNUM
    10 7782 *1* *1*
    10 7839 *2* *2*
    10 7934 *3* *3*
    20 7369 *4* *1*
    20 7876 *5* *2*
    20 7902 *6* *3*
    20 7788 *7* *4*
    20 7566 *8* *5*
    30 7499 *9* *1*
    30 7698 *10* *2*
    30 7654 *11* *3*
    30 7900 *12* *4*
    30 7844 *13* *5*
    30 7521 *14* *6*
    14 rows selected.

    SQL> select emp.deptno, emp.empno,
      2    row_number() over(order by emp.deptno, emp.empno) rn,
      3    row_number() over(partition by emp.deptno order by emp.empno) dept_rn
      4  from emp, dept
      5  where emp.deptno=dept.deptno
      6  order by emp.deptno, emp.empno;
        DEPTNO      EMPNO         RN    DEPT_RN
            10       7782          1          1
            10       7839          2          2
            10       7934          3          3
            20       7369          4          1
            20       7566          5          2
            20       7788          6          3
            20       7876          7          4
            20       7902          8          5
            30       7499          9          1
            30       7521         10          2
            30       7654         11          3
            30       7698         12          4
            30       7844         13          5
            30       7900         14          6
    14 rows selected.Regards,
    Dima

  • Query  for getting records  max  reported  timestamp and 2nd max report

    query for getting records in between
    max reported timestamp and 2nd max reported timestamp
    HERE IS ALL RESULT SET
    TIME DOMAIN
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    QUERY RESULT TO COME
    TIME DOMAIN
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    Message was edited by:
    user517983

    Hi,
    can we write query like this.
    1 select pd_user,PD_REPORTED_TIMESTAMP
    2 from sp_process_detail_current spdc
    3 where host_id='DSCP02469'and pd_user='TOMCAT'
    4 and exists(
    5 select PD_REPORTED_TIMESTAMP from sp_process_detail_current
    6* having max(PD_REPORTED_TIMESTAMP)-spdc.PD_REPORTED_TIMESTAMP=0)
    SQL> /
    PD_USER PD_REPORTED_TIMESTAM
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45

  • Functional module for Getting Material classification data.

    Please tell me Functional module for Getting Material classification data like class type , class, characteristics and characteristics values for material.

    Dear,
    FM:
    CLAF_CLASSIFICATION_OF_OBJECTS
    Table KLAH Class Header Data
    - KSML Characteristics of a Class
    Regards,
    R.Brahmankar

  • Query for getting address from RA_CUSTOMER_TRX_ALL.REMIT_TO_ADDRESS_ID

    Some one please provide query for getting REMIT TO ADDRESS details by using the column RA_CUSTOMER_TRX_ALL.REMIT_TO_ADDRESS_ID

    try
    select ct.remit_to_address_id,
           raa_remit_ps.party_site_number,
           raa_remit_loc.state,
           ft_remit.territory_short_name,
           ct.*
      from ra_customer_trx_all    ct,
           hz_cust_acct_sites_all raa_remit,
           hz_party_sites         raa_remit_ps,
           hz_locations           raa_remit_loc,
           fnd_territories_vl     ft_remit
    where 1 = 1
       and ct.remit_to_address_id = raa_remit.cust_acct_site_id(+)
       and raa_remit.party_site_id = raa_remit_ps.party_site_id(+)
       and raa_remit_loc.location_id(+) = raa_remit_ps.location_id
       and raa_remit_loc.country = ft_remit.territory_code(+)

  • Query for getting Responsibility, Menu and submenus

    Hi,
    I need one query for getting Responsibilites, menus, submenus agian submenus like that..
    Pls share the query any body have.
    Thanks in advance,
    Hanimi.

    See user487104's post in Re: How to check a function is accessible under responsibility? .
    He has given a script to build the output.

  • Query for Getting previous date in oracle in specifc scenario

    I have the below data in a table A which i need to insert into table B along with one compute column.
    TABLE A:
    Account_No | Balance | As_on_date
    1001 |-100 | 1-Jan-2013
    1001 |-150 | 2-Jan-2013
    1001 | 200 | 3-Jan-2013
    1001 |-250 | 4-Jan-2013
    1001 |-300 | 5-Jan-2013
    1001 |-310 | 6-Jan-2013
    Table B:
    In table B,there should be no of days to be shown when balance is negative and the date one which it has gone into negative.
    So,for 6-Jan-2013,this table should show below data:
    Account_No | Balance | As_on_date | Days_passed | Start_date
    1001 | -310 | 6-Jan-2013 | 3 | 4-Jan-2013
    Here,no of days should be the days when the balance has gone negative in recent time and not from the old entry.
    I need to write a sql query to get the no of days passed and the start date from when the balance has gone negative.
    I tried to formulate a query using Lag analytical function,but i am not getting how should i check the first instance of negative balance by traversing back using LAG function. Even the first_value function was given a try but not getting how to partition in it based on negative value.
    Any help or direction on this will be really helpful.
    Thanks

    I think you can apply the Tabibitoshan method here. The query is more complex but performs better than other methods. For an explanation, see Tabibitosan method tutorial by Aketi Jyuuzou
    The idea behind the method is to identify "continuous" records without gaps. Here I identify records that are "continuous" because they contain an uninterrupted series of negative balances.
    drop table t;
    CREATE TABLE t (Account_No , Balance , As_on_date) AS SELECT
    1001 ,-100 , to_date('1-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-150 , to_date('2-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 , 200 , to_date('3-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-250 , to_date('4-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-300 , to_date('5-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-310 , to_date('6-Jan-13', 'DD-MON-YY') FROM dual;
    SELECT Account_No, Balance, to_char(As_on_date, 'DD-MON-YYYY') as_on_date,
    CASE
      WHEN balance < 0
      THEN row_number() OVER(PARTITION BY account_no, grp ORDER BY as_on_date)
    END days_passed,
    CASE
      WHEN balance < 0
      THEN to_char(
        first_value(as_on_date) OVER(PARTITION BY account_no, grp ORDER BY as_on_date),
        'DD-MON-YYYY'
    end start_date
    from (
      SELECT Account_No, Balance, As_on_date,
      CASE WHEN balance >= 0 THEN NULL ELSE
        row_number() OVER(PARTITION BY account_no ORDER BY as_on_date) -
        sum(CASE WHEN balance < 0 THEN 1 ELSE 0 END) OVER(PARTITION BY account_no ORDER BY as_on_date)
      end grp
      FROM t
    order by account_no, As_on_date;
    ACCOUNT_NO
    BALANCE
    AS_ON_DATE
    DAYS_PASSED
    START_DATE
    1001
    -100
    01-JAN-2013
    1
    01-JAN-2013
    1001
    -150
    02-JAN-2013
    2
    01-JAN-2013
    1001
    200
    03-JAN-2013
    1001
    -250
    04-JAN-2013
    1
    04-JAN-2013
    1001
    -300
    05-JAN-2013
    2
    04-JAN-2013
    1001
    -310
    06-JAN-2013
    3
    04-JAN-2013

  • Query for getting data for every quarter for financial year

    Hi,
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.
    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.

    lakmesri wrote:
    Hi,
    My problem is I need to get the data for every quarter for financial year and also I need data for every week for financial year.
    For example for financial year 2012-13, Apr2012 to Jun2012 would be Q1, Jul2012 to Sep2012 would be Q2 and so on. Total 8quarters should come upto Apr2013.
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.
    How can you get 8 quarters within a year ? I'b be concerned here.
    lakmesri wrote:
    Hi,
    In the same way  1st apr 2012 to 7th apr 2012 would be week1, 8th apr to 15th apr would be week2 and son on. How to write a query for this scenario in oracle. Can anybody help me on this. very urgent..
    Thanks in advance.
    First, that question is really not clearly asked. Second how could it be urgent ? You even did not tell us your Oracle version, did not show any tables descr, output sample nor any effort on your side to work on.
    Nicolas.

  • Help in query to get the max(date)

    Hi I have query like below and based on the query I get the following results,
    SELECT a.UsageId,a.product,ProductDate
    FROM dbo.table1 a
    JOIN dbo.table2 b ON a.SID= b.SID
    JOIN dbo.table3 c ON b.CID = c.CID
    UsageId        Product          UsageDate
    1 Yellow 2014-01-01
    2 Yellow 2014-01-02
    3 Yellow 2014-01-03
    4 Yellow 2014-01-04
    5 Red 2014-01-01
    6 Red 2014-01-02
    7 Blue 2014-01-03
    8 Blue
    2014-01-04
    Now I want to add a new column which gives me the Max(UsageDate) of the column Prdouct last Usage.
    UsageId        Product          UsageDate          Max(UsageDate)
    1 Yellow
    2014-01-01          2014-01-04
    2 Yellow
    2014-01-02    2014-01-04
    3 Yellow
    2014-01-03          2014-01-04
    4 Yellow
    2014-01-04          2014-01-04
    5 Red 2014-01-01          2014-01-02 
    6 Red 2014-01-02          2014-01-02
    7 Blue
    2014-01-03          2014-01-04
    8 Blue
    2014-01-04          2014-01-04

    Simply use:
    SELECT a.UsageId,a.product,ProductDate, MAX(ProductDate) OVER (PARTITION BY a.ProductID) as [Latest Product Usage Date]
    FROM dbo.table1 a
    JOIN dbo.table2 b ON a.SID= b.SID
    JOIN dbo.table3 c ON b.CID = c.CID
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Which type of setting we need to maintain in query to get Multi Provider data

    HI Friends.
    I created query on top of Multi Provider. Multi Provider created on top of Hybrid provider and Standard cube.
    When i executed the Query on top Multi Provider, i can't see the data of Hybrid Provider through Query.
    In BW side i can see the data on Multi provider.
    Can any one help me.

    Hi,
    First need to understand what is the use of Hybrid Provider in what cases we prefer provider.
    Multiprovider  :can be created based on DSO & Infocube
    Hybrid Provider : Can Be created based on DSO / HybridProviders based on direct access.
    For more Info on Hybrid Provider : Creating HybridProviders - Modeling - SAP Library
    There are no settings to get Hybrid provider data Or Multiprovider data in Bex .
    Even though if we need to do any settings we can do it in SPRO , check once in SPRO tcode related to Bex reporting  settings.
    Regards,
    Seshu.P

  • Oracle SQL query for getting specific special characters from a table

    Hi all,
    This is my table
    Table Name- Table1
    S.no    Name
    1          aaaaaaaa
    2          a1234sgjghb
    3          a@3$%jkhkjn
    4          abcd-dfghjik
    5          bbvxzckvbzxcv&^%#
    6          ashgweqfg/gfjwgefj////
    7          sdsaf$([]:'
    8          <-fdsjgbdfsg
    9           dfgfdgfd"uodf
    10         aaaa  bbbbz#$
    11         cccc dddd-/mnm
    The output has to be
    S.no    Name
    3          a@3$%jkhkjn
    5          bbvxzckvbzxcv&^%#
    7          sdsaf$([]:'
    8          <-fdsjgbdfsg
    10         aaaa  bbbbz#$
    It has to return "Name" column which is having special characters,whereas some special chars like -, / ," and space are acceptable.
    The Oracle query has to print columns having special characters excluding -,/," and space
    Can anyone help me to get a SQL query for the above.
    Thanks in advance.

    You can achieve it in multiple ways. Here are few.
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'aaaaaaaa' name from dual union all
      5  select 2 id, 'a1234sgjghb' name from dual union all
      6  select 3 id, 'a@3$%jkhkjn' name from dual union all
      7  select 4 id, 'abcd-dfghjik' name from dual union all
      8  select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
      9  select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
    10  select 7 id, 'sdsaf$([]:''' name from dual union all
    11  select 8 id, '<-fdsjgbdfsg' name from dual union all
    12  select 9 id, 'dfgfdgfd"uodf' name from dual union all
    13  select 10 id, 'aaaa  bbbbz#$' name from dual union all
    14  select 11 id, 'cccc dddd-/mnm' name from dual
    15  )
    16  select *
    17    from t
    18   where regexp_like(translate(name,'a-/" ','a'), '[^[:alnum:]]');
            ID NAME
             3 a@3$%jkhkjn
             5 bbvxzckvbzxcv&^%#
             7 sdsaf$([]:'
             8 <-fdsjgbdfsg
            10 aaaa  bbbbz#$
    SQL> with t
      2  as
      3  (
      4  select 1 id, 'aaaaaaaa' name from dual union all
      5  select 2 id, 'a1234sgjghb' name from dual union all
      6  select 3 id, 'a@3$%jkhkjn' name from dual union all
      7  select 4 id, 'abcd-dfghjik' name from dual union all
      8  select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
      9  select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
    10  select 7 id, 'sdsaf$([]:''' name from dual union all
    11  select 8 id, '<-fdsjgbdfsg' name from dual union all
    12  select 9 id, 'dfgfdgfd"uodf' name from dual union all
    13  select 10 id, 'aaaa  bbbbz#$' name from dual union all
    14  select 11 id, 'cccc dddd-/mnm' name from dual
    15  )
    16  select *
    17    from t
    18   where translate
    19         (
    20            lower(translate(name,'a-/" ','a'))
    21          , '.0123456789abcdefghijklmnopqrstuvwxyz'
    22          , '.'
    23         ) is not null;
            ID NAME
             3 a@3$%jkhkjn
             5 bbvxzckvbzxcv&^%#
             7 sdsaf$([]:'
             8 <-fdsjgbdfsg
            10 aaaa  bbbbz#$
    SQL>

  • EIS - Is this the solution for getting to Alpha data?

    Is there any other way to get to alpha data(stored in FISERV), through Essbase?

    As Jeff mentioned, unfortunately, the info provided is incorrect. Most external hard drives do not have the ability to act as a host device. Meaning, when you plug your camera into a computer, it generally mounts the camera as a drive (or provides similar functionality). You then use your computer to pull the information from the camera. If you simply connect an external drive directly to the camera (as this solution suggests), there is no way to get the data from the camera to the drive. You can generally daisy chain firewire connections... meaning you can connect your camera to a firewire drive and if the firewire drive has multiple firewire ports, you can then connect the second port to a computer with firewire. This is not an option for you as you already know there is no firewire on the MacBook. There is some misconception that for external drives with multiple interfaces (firewire and USB and or eSATA) that you can connect a camera to the drives firewire interface and then connect the drive to your computer using the USB connection. Unfortunately, you can't daisy chain across different interfaces, the drive can only support data throughput through one interface at a time.
    Still an external drive is good to have for backups, etc... but it is not a solution for your problem.

Maybe you are looking for