Using SQL to ensure the matching records are mutually exclusive.

There are two tables defined in the following way:

Table A

Number 1

Number 2

Date

ROWID

Table B

Number 1

Number 2

Date

Identifier of the line

Each table stores a call between number 1 and 2 on a specific date. The goal is to map exactly one entry of table A with exactly the record in table B

in a mutually exclusive way. So a single call to a table must be associated with exactly one call the other table (the key is here

A.Number1 is B.Number1 and A.Number2 = B.Number2). Because it is a relationship is many to many (the number of source and destination may be paired multiple)

(time), I'm not able to build a series of sql statements that will allow me to get a relationship one between pairs of telephone numbers.

I'm not allowed to develop a PL/SQL procedure, which would easily solve this problem.

I was able to find a solution using MIN(Number 1) KEEP (DENSE_RANK FIRST ORDER BY Date) to THE (PARTITION BY x) the form x

using temporary tables, which allows me to reach a breaking successively much many relationships (i.e. three broken bones in a 01:58 after

an iteration, and after one iteration, I arrive at a one to one relationship). However, I can't break these relations some n number of times because it requires number n

hard curls. Therefore, I need a sophisticated solution that will allow me to achieve a relationship one by one.

Example of

Table A

Record 1

Number 1:451923456789

Number 2:541969432045

Date: 29/07/2015-09:01

Worksheet 2

Number 1: 451923456789

Number 2: 541969432045

Date: 29/07/2015-09:03

Table B

Record 1

Number 1: 451923456789

Number 2: 541969432045

Date: 29/07/2015-09:04

Worksheet 2

Number 1: 451923456789

Number 2: 541969432045

Date: 29/07/2015-09:05

If we unite our table A and B by A.Number1 = B.Number1 and A.Number2 = B.Number2, we have 4 records. I'm looking for exactly two records.

The criteria is to associate by the minimum of the sum of the date of the table A table B date. Therefore, the final result should match:

(1) record 1 of table A with record 1 of table B.

sheet 2) 2 table A with 2 record in table B.

So we must do something to reduce the 4 records resulting from the join of two records describe as we see above.

The result of the join:

1st row: TableA.Record1 with TableB.Record1

2nd place: TableA.Record1 with TableB.Record2

Rank 3: TableA.Record2 with TableB.Record1

4th place: TableA.Record2 with TableB.Record2

What I'm looking for, which is easily achievable with a slider, but not with SQL:

1st row: TableA.Record1 with TableB.Record1

4th place: TableA.Record2 with TableB.Record2

Note that if the minimum date condition allows us to select the necessary records, we won't get the expected results. In other words, using the minimum date.

the results will be:

1st row: TableA.Record1 with TableB.Record1

Rank 3: TableA.Record2 with TableB.Record1

(criteria - table a minimum date)

or

1st row: TableA.Record1 with TableB.Record1

2nd place: TableA.Record1 with TableB.Record2

(criteria - date minimum table B)

Two of these results to break the rule are mutually exclusive.

Post edited by: 3000640

If I understand correctly, something like:

SQL > with tableA (id, telephone1, telephone2, call_date) as)

2. Select 1, ' 451923456789 ', ' 541969432045',

3 to_date (July 29, 2015 09:01 ', 'dd.mm.yyyy hh24')

4 union double all the

5. Select 2, ' 451923456789 ', ' 541969432045',

6 to_date (July 29, 2015 09:03 ', 'dd.mm.yyyy hh24')

double 7),

TableB 8 (id, telephone1, telephone2, call_date) as)

9. Select 1, ' 451923456789 ', ' 541969432045',

10 to_date (July 29, 2015 09:04 ', 'dd.mm.yyyy hh24')

11 double Union all the

12. Select 2, ' 451923456789 ', ' 541969432045',

13 to_date (July 29, 2015 09:05 ', 'dd.mm.yyyy hh24')

14 double)

15 select a.id help, a.phone1 aphone1, a.phone2 aphone2,

16 a.call_date acall_date, b.id offer, b.phone1 bphone1,

17 b.phone2 bphone2, b.call_date bcall_date

18 (select id, telephone1, telephone2, call_date,

19 row_number() over (partition by numbers1, telephone2

RN 20 order by call_date)

tablea 21) a

22 join (select id, telephone1, telephone2, call_date,

23 row_number() over (partition by numbers1, telephone2

RN 24 order by call_date)

tableb 25) b

26 on a.phone1 = b.phone1 and

27 a.phone2 = b.phone2 and

28 a.rn = b.rn;

HELP APHONE1 APHONE2 ACALL_DATE BPHONE1 BPHONE2 BCALL_DATE OFFERS

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

1 451923456789 541969432045 July 29, 2015 09:01 1 451923456789 541969432045 July 29, 2015 09:04

2 451923456789 541969432045 July 29, 2015 09:03 2 451923456789 541969432045 July 29, 2015 09:05

John

Tags: Database

Similar Questions

  • How can I use SQL to check the Version of Oracle Forms and object of the request?

    Hi all:

    How can I use SQL to check the Version of Oracle Forms and object of the request?





    Concerning
    Terry

    Terry,

    See the following threads/docs for the version of forms.

    How to find the developer version
    Re: How to find the developer version

    Note: 466890.1 - Script to find the Apache, Java, Jinitiator, version of forms and details of the JVM for Oracle E-Business Suite 11i
    Note: 392793.1 - how to get Forms Oracle Oracle Applications 11i Command Line Version
    Note: 468311.1 - Script to find the Apache, Java, JRE, Forms for Oracle E-Business Suite R12 version

    What purpose are you talking?

    Thank you
    Hussein

  • A license is required at the VASA? A license is required for each copy? VSI is necessary to have the VASA? They are mutually exclusive? VSI need NOTTM?

    A license is required at the VASA? A license is required for each copy? VSI is necessary to have the VASA? They are mutually exclusive? VSI need NOTTM?

    Thanks in advance.

    Assuming that you are referring to EMC arrays.

    License to the VASA: No.

    VSI required at the VASA: No. they work very well together, but does require that the other.

    VSI allowing VAAI: No. VAAI is active with or without the VSI.

  • report based on elements are mutually exclusive:

    Hi guys,.
    I am creating a parameterized report based on elements are mutually exclusive:

    I have a list select 'P1_Property_type' element that has these values (office, apartment)
    If you choose "desktop" then the report should ONLY the value of the selection list element 'P1_beds '.
    If you choose 'apartment' then the report should be considered AS the value of the selection list "P1_size."
    ----------
    I used this query, but it does not seem to contribute:
    Select * from realestate where
    unit_type = decode (: P1_PROPERTY_TYPE, 'null', unit_type,: P1_property_type)
    and
    (br = decode (: P1_beds, "null", br,: P1_beds) or size = decode (: P1_size, 'null', size,: P1_size))
    ----------------
    I hope my question is clear

    Kind regards
    Fateh

    Assuming you are using the literal string "null" instead of NULL.

    "it doesn't seem to work" because of this:

    (br = decode (: P1_beds, "null", br,: P1_beds) or size = decode (: P1_size, 'null', size,: P1_size))

    Assuming you choose 'office' and: has the value p1_beds and: p1_size is "null", you end up with a statement that is the equivalent of:

    select * from realesate
    where unit_type = 'office'
    and (br = :p1_beds
    or size=size)    <--------------problem
    

    and your: p1_beds restriction is so inefficient.

    I'm not a fan of decode for this logic.
    I prefer a clear statement of the exclusive predicates that the optimizer can sometimes deal more effectively.

    for example, assuming that it is irrelevant, if you choose office or apartment because the relevant parameter: p1_beds or: p1_size will have the appropriate value:

    select * from realestate
    where
          (:p1.property_type is null / = 'null'
    or    (:p1.property_type is not null / != 'null'
    and    unit_type          = :p1_property_type))
    and   (:p1_beds          is null / = 'null'
    or    (:p1_beds          is not null / != 'null'
    and    br                 = :p1_beds))
    and   (:p1_size          is null / = 'null'
    or    (:p1_size          is not null / != 'null'
    and    size               = :p1_size))
    

    Note that I have provided alternatives depending on whether you are actually the NULL or a magic string.

  • Find the matching record better

    create table data(item_no int,item_size varchar2(10),color varchar2(10));
    
    insert into data values (1,null,null);
    
    insert into data values (1,'small',null);
    
    insert into data values (1,null,'pink');
    
    insert into data values (1,'large','red');
    
    create table filters(item_no int,item_size varchar2(10),color varchar2(10),comments varchar2(100));
    
    insert into filters values (1,null,null,'all sizes and colors');
    
    insert into filters values (1,'small',null,'small comment');
    
    insert into filters values (1,null,'pink','love pink');
    
    insert into filters values (1,'large','red','large red comment');
    
    select
    d.item_no,d.item_size,d.color,f.comments
    from data d,filters f
    where d.item_no=f.item_no(+)
    and d.item_size = f.item_size(+)
    and d.color = f.color(+);
    
    

    How would I go about matching records in the data table with the best matching filter table record? Best way where the majority of the attributes match (item_no, item_size and color). I thought a simple outer join would, but it does not quite what I need.

    What Miss me? Thank you

    Hello

    Thanks for posting the sample data.

    Don't forget to post the exact results you want from these data.

    One thing you can do is a Top - N query, like this:

    WITH got_r_num AS

    (

    SELECT d.item_no, d.item_size, d.color, f.comments - or other

    ROW_NUMBER () (PARTITION BY d.ROWID - OR primary key,

    IN CASE of ORDERS WHEN d.item_no = f.item_no THEN 1 END ELSE 0

    + CASE WHEN d.item_size THEN 1 END ELSE f.item_size = 0

    + CASE WHEN d.color THEN 1 END ELSE f.color = 0

    --+... If you have other attributes

    / / DESC

    ) AS r_num

    DATA d

    CROSS JOIN filters f

    )

    SELECT item_no, item_size, color, comments

    OF got_r_num

    WHERE r_num = 1

    ;

    I would like a unique identifier to each table, and I had want to display in the results.

    Remember, in SQL if x or y is NULL then

    x = y

    won't be TRUE.  If you want NULL in two tables to match anything in the other table, then the same general approach will work, but it is messier.

    What results do you want to tie (i.e. for a given line in d, 2 or several lines of f have exactly the same number of corresponding attributes)?

    If this number is 0?

  • Sound on my laptop is not as strong that used to be, all the sound settings are set to high

    Hi my laptop is a hp g6 on windows 7 64 bit.

    My problem is that my volume seems not to be so strong that used to be, all the settings of the machine are set to full volume. the only thing I can think is the software I have installed all the latest drivers can have down loaded a wrong?

    concerning

    DigitalKen

    P/S, please help it's driving me crazy, lol

    Hello

    One thing that may help is the following: If this option is available depends on the IDT pilot.

    Do a right-click the speaker icon in the taskbar and select "playback devices".  Left click the device once to highlight default (it is usually 'speakers & headphones') and then click the properties button.  Click the enhancements tab and put a check mark in the box "Loudness equalization.  Click on apply to save the changes and then click OK in all other windows and see if allowed at all.

    Kind regards

    DP - K

  • Using SQL to display the date range

    Gurus,

    I have a sql statement such as
    select MIN(HIREDATE), MAX(HIREDATE) FROM EMP WHERE DEPTNO = 30
    My output looks like
    MIN(HIREDATE)     MAX(HIREDATE)
    
    12/30/1998        12/30/2001
    Based on the values of MIN (HIREDATE), MAX (HIREDATE) values
    I need a SQL to generate the output as

    30/12/1998
    30/01/1999
    28/02/1999
    ---
    ---
    until the Max value (HIREDATE)

    In February, we have 30 days, in this case to the last day of the month.

    Thanks for the great help
    C 007

    Hello

    put my post to correct and others with useful, please

    Is salim.

  • Drop-down menus are mutually exclusive

    Hi all:

    I am working on a form in which I need to have a user rates four items 1 to 4 compared to the other. Initially, we were going to use 4 drop downs each menu containing four options allowing the user to choose. The problem is, of course, that the user could choose option 1 four times in a row. So I need a way to allow the user to assess these four points 1 to 4, but in a mutually exclusive way. the image below shows the problem (they are in Spanish, but the text is not important). Here point 1 and section 4 have been selected both as 1, which is what we want to avoid. Any suggestions would be greatly appreciated. Thank you.

    4choices.png

    Hello

    You could have a script of the event preOpen all of the four drop-down menus that would set the display settings, based on the previous selections in the other drop-down menus.

    There is an example here to populate the drop-down menus: http://assure.ly/jcTahK.

    Try this in the DropDownList1 preOpen event:

    Remove the previously selected items

    this.deleteItem (DropDownList2.selectedIndex);

    this.deleteItem (DropDownList3.selectedIndex);

    this.deleteItem (DropDownList4.selectedIndex);

    Hope that helps,

    Niall

  • whether the updated records are new values

    I'm using Oracle 11.2.0.4.

    update of table tmp_tbl

    the value of col1 = new_value

    I want to know if there are ways to tell if an update was updated again, IE <>new_value col1 values by.   I know that I can add where col1 <>new_value and base on sql % rowcount, I can understand if the update happen. However, due to the number of columns and the tables involved, we are looking for other ways.

    Previously, we have accomplished this by using less and flashback query.

    insert into tmp_tbl (ID, K1) values (1, "OLD_VALUE")

    commit;  / * Note, we do not now have, so we are not able to use flashback query and looking for other more easy solution other than comparing each column for all the table * /.

    Update tmp_tbl

    the value of col1 = new_value

    where id = 1

    Yvert returning in v_scn;


    Select count (*) in the v_cnt of)

    Select * from tmp_tbl from SNA v_scn where id = 1

    less

    Select * from tmp_tbl where id = 1)

    IF v_cnt > 1

    v_data_changed_flag = TRUE;

    END IF:

    Now, this must be done within the same transaction, so there is no commit. It seems that the flashback query access only committed data, so we couldn't use flashback queries.

    Thanks in advance.

    Post edited by: spur230

    If you just want to know some updated column, but not necessarily who, you can store a checksum for each line and check in a trigger, maybe?

    OWA_OPT_LOCK

    http://blog.sydoracle.com/2011/06/check-summing-table-row.html

    If you need to know what columns have been updated, you will have to do a hash as they show here.

  • Revel and iCloud are mutually exclusive?

    I installed Adobe Revel on my iPhone 4 (ios 6.1.3) and now iCloud does not synchronize my photos with my Win7 PC.

    Revel seems to work ok, but I didn't really replace iCloud

    Pete,

    Revel/service app shouldn't have an effect to the iCloud service. Have you tried to sign out and then sign back in to your iCloud service? This happens when you are connected to Revel? Glad to hear that Revel works well for you on your pc.

    Let me know if you have other questions about the use of Revel

    Thank you

    Scott

  • Turn Windows features on or off - games and IE are mutually exclusive?

    When I activate the games help to turn Windows features on or off, IE11 is deleted from my computer and is no longer visible as an option to activate Windows features On or Off.  It is a 2 - day old HP Probook running Windows 7 Professional.

    I need to restore to recover IE11 on my machine.  I did this four times now.  100% reproducible.

    Any ideas?

    Okay, I think that all is well now.

    I turned on the game, uninstalled IE11 from Windows Update and reinstalled IE11 using offline Installer.

    The games and IE11 work.  IE11 appears even to turn features Windows turn on or off.

    Thanks for the help and suggestions!

  • Demonstrating the PL/SQL using SQL Developer functions

    Good afternoon

    I started writing some PL/SQL functions to replace some of the SQL I use most often.  Some very simple examples would be:

    create or replace function func_test (p_1 number) return number
    
    is
    
    x number;
    y number;
    
    begin
    
    
    x :=1;
    y :=2;
    
    
    return p_1 * x * y;
    
    
    end func_test;
    
    

    create or replace function func_test2 (p_1 varchar2) return varchar2
    
    
    is
    
    
    return_val varchar2(10);
    
    
    begin
    
    
    select p_1 into return_val from dual;
    
    
    return return_val;
    
    
    end func_test2;
    

    However, on my place of work that I have not been granted created function privileges again until I can show some examples, which is understandable.

    For the moment, without these privileges, is there a way I can build/test functions in principle locally using SQL Developer without the need to write functions in our database? I.e. can demonstrate meanings in SQL Developer, but devoid of envelope to create or syntax of replace?

    I hope that's not too vague.

    Using Oracle 11 g 2 (not connected to the database of the workplace at this time for a specific version not.)

    3.4 SQL Developer

    Thank you

    TP

    Hello

    The obvious solution is to get privileges.  If your employer wants to do you something, they give you the necessary privileges to do so.  It's silly for them to tell you to do something, but refuses to let you do.

    Otherwise, you can install Oracle on your own machine, as suggested above.  It's free and legitimate, if you only use it for learning and development.  Oracle Express Edition is very easy to install.

    As a last resort, you can write functions and procedures that are local to an anonymous block, like this:

    SET SERVEROUTPUT ON

    DECLARE
    Function func_test (p_1 number) return number
    is
    x number;
    number of y;
    Start
    x: = 1;
    y: = 2;
    return p_1 * x y;
    end func_test;
    BEGIN
    dbms_output.put_line (func_test (3))
    || '= func_test results.
    );
    END;
    /

    You can only call this kind of function of the anonymous block in which it is defined.

  • SQL * sequential data Loader in the treatment Record file?

    If I use the will of classic way SQL * Loader process a data file in the order from top to bottom?  I have a file with header and the detail records without value found in the detail records that can be used to connect to the header records.  The only option is to derive a header value via a sequence (nextval) and then fill in the detail records with the same value from the same sequence (currval).  But to do SQL * Loader should treat the file in the exact order that the data has been written to the data file.  I read through the 11 g Oracle® database utilities SQL * Loader sections looking for evidence that this is what's going to happen, but have not found this information and I don't want to assume that SQL * Loader will always process the data file records in order.

    Thank you

    Support of Oracle responded with the following statement.

    "Yes, SQL * LOADER file data from top down process."
    This has been affected in the note below:

    "SQL * Loader - how to load a single logical record physical records line breaks include (Doc ID 160093.1).

    Jason

  • The configuration files are used to create this cache server?

    I start a cache server by running the $COHERENCE_HOME/bin/cache-server.sh file. But I don't how it is configured.
    The configuration files are used to create this cache server? How do I know?
    I check the contents of the cache-.sh file.
    In my view, the config.xml file - cache-coherence, consistency-pof - config.xml file and leader tangosol-coherence are used, no?

    After the start of a cache server, view the output carefully and you will find the configuration files are used. For example, the configuration files are displayed in bold background in the following text:

    F:\coherence\coherence\bin>cache-server.cmd
    java version "1.6.0_16"
    Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
    Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)
    
    2009-11-30 22:46:06.468/1.547 Oracle Coherence 3.5/459  (thread=main, member=n/a): Loaded oper
    ational configuration from resource "jar:file:/F:/coherence/coherence/lib/coherence.jar!/ *tangosol-co*
    *herence.xml"*
    2009-11-30 22:46:06.484/1.563 Oracle Coherence 3.5/459  (thread=main, member=n/a): Loaded oper
    ational overrides from resource "jar:file:/F:/coherence/coherence/lib/coherence.jar!/ *tangosol-cohere*
    *nce-override-dev.xml"*
    2009-11-30 22:46:06.500/1.579 Oracle Coherence 3.5/459  (thread=main, member=n/a): Optional conf
    iguration override "/tangosol-coherence-override.xml" is not specified
    2009-11-30 22:46:06.500/1.579 Oracle Coherence 3.5/459  (thread=main, member=n/a): Optional conf
    iguration override "/custom-mbeans.xml" is not specified
    
    Oracle Coherence Version 3.5/459
     Grid Edition: Development mode
    Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
    
    2009-11-30 22:46:07.468/2.547 Oracle Coherence GE 3.5/459  (thread=main, member=n/a): Loaded c
    ache configuration from resource "jar:file:/F:/coherence/coherence/lib/coherence.jar!/ *coherence-cach*
    *e-config.xml"*
    2009-11-30 22:46:08.515/3.594 Oracle Coherence GE 3.5/459  (thread=Cluster, member=n/a): Service
     Cluster joined the cluster with senior service member n/a
    2009-11-30 22:46:11.765/6.844 Oracle Coherence GE 3.5/459  (thread=Cluster, member=n/a): Creat
    ed a new cluster "cluster:0xD7DB" with Member(Id=1, Timestamp=2009-11-30 22:46:08.109, Address=192.1
    68.0.8:8088, MachineId=26632, Location=site:localdomain,machine:host1,process:1060, Role=CoherenceSe
    rver, Edition=Grid Edition, Mode=Development, CpuCount=1, SocketCount=1) UID=0xC0A800080000012548585
    C6D68081F98
    2009-11-30 22:46:11.796/6.875 Oracle Coherence GE 3.5/459  (thread=Invocation:Management, member
    =1): Service Management joined the cluster with senior service member 1
    2009-11-30 22:46:12.515/7.594 Oracle Coherence GE 3.5/459  (thread=DistributedCache, member=1):
    Service DistributedCache joined the cluster with senior service member 1
    2009-11-30 22:46:12.593/7.672 Oracle Coherence GE 3.5/459  (thread=ReplicatedCache, member=1): S
    ervice ReplicatedCache joined the cluster with senior service member 1
    2009-11-30 22:46:12.609/7.688 Oracle Coherence GE 3.5/459  (thread=OptimisticCache, member=1): S
    ervice OptimisticCache joined the cluster with senior service member 1
    2009-11-30 22:46:12.625/7.704 Oracle Coherence GE 3.5/459  (thread=Invocation:InvocationService,
     member=1): Service InvocationService joined the cluster with senior service member 1
    2009-11-30 22:46:12.625/7.704 Oracle Coherence GE 3.5/459  (thread=main, member=1): Started De
    faultCacheServer...
    
    SafeCluster: Name=cluster:0xD7DB
    
    Group{Address=224.3.5.0, Port=35459, TTL=4}
    
    MasterMemberSet
      (
      ThisMember=Member(Id=1, Timestamp=2009-11-30 22:46:08.109, Address=192.168.0.8:8088, MachineId=266
    32, Location=site:localdomain,machine:host1,process:1060, Role=CoherenceServer)
      OldestMember=Member(Id=1, Timestamp=2009-11-30 22:46:08.109, Address=192.168.0.8:8088, MachineId=2
    6632, Location=site:localdomain,machine:host1,process:1060, Role=CoherenceServer)
      ActualMemberSet=MemberSet(Size=1, BitSetCount=2
        Member(Id=1, Timestamp=2009-11-30 22:46:08.109, Address=192.168.0.8:8088, MachineId=26632, Locat
    ion=site:localdomain,machine:host1,process:1060, Role=CoherenceServer)
        )
      RecycleMillis=120000
      RecycleSet=MemberSet(Size=0, BitSetCount=0
        )
      )
    
    Services
      (
      TcpRing{TcpSocketAccepter{State=STATE_OPEN, ServerSocket=192.168.0.8:8088}, Connections=[]}
      ClusterService{Name=Cluster, State=(SERVICE_STARTED, STATE_JOINED), Id=0, Version=3.5, OldestMembe
    rId=1}
      InvocationService{Name=Management, State=(SERVICE_STARTED), Id=1, Version=3.1, OldestMemberId=1}
      DistributedCache{Name=DistributedCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCo
    unt=257, BackupCount=1, AssignedPartitions=257, BackupPartitions=0}
      ReplicatedCache{Name=ReplicatedCache, State=(SERVICE_STARTED), Id=3, Version=3.0, OldestMemberId=1
    }
      Optimistic{Name=OptimisticCache, State=(SERVICE_STARTED), Id=4, Version=3.0, OldestMemberId=1}
      InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=5, Version=3.1, OldestMember
    Id=1}
      )
    
  • SQL query for the set of data rows not values

    Hello!

    I use Oracle 10 g (10.2.0.1.0) and I need help to solve this difficult task. I have a huge table with more than 145000 records and I shows you only a sample of it:

    ID TEAMNAME_EN DT TEAMNAME_EN HPROB AM APROB FT
    324813 31/8 / 2012 DEN HAAG GRONINGEN 1.90 3.30 3.10 2
    324823 31/8 / 2012 MAINZ GREUTHER FÜRTH 1.75 3.25 3.65 2
    324805 31/8 / 2012 GAZELEC DIJON 1.60 3.15 4.75 1
    324810 31/8 / 2012 ÖREBRO DJURGÅRDEN 2.80 3.25 2 2.05
    324795 31/8 / 2012 FC KÖLN COTTBUS 1.85 3.20 3.35 2
    324837 31/8 / 2012 PORTLAND WOOD COLORADO RAPIDS 2,00 3.20 2.95 1
    324828 31/8 / 2012 DROGHEDA UNITED, DUNDALK 1.45 3.65 5.25 1
    324827 31/8 / 2012 CORK CITY SHAMROCK ROVERS 3,30 3,80 1.70 2
    324833 31/8 / 2012 BARUERI ASA 2.45 3.20 1-2.30
    324798 31/8 / 2012 GENÇLERBIRLIGI ORDUSPOR'A 2.00 3,10 X 3.00
    324814 31/8 / 2012 ALMERE CITY FC OSS 1,80 3,50 3,20 2
    324830 31/8 / 2012 CRICIÚMA BRAGANTINO 1.25 4.35 1 8.00
    324820 31/8 / 2012 VOLENDAM FC EINDHOVEN 1.80 3.25 3.45 1
    324818 31/8 / 2012 MVV MAASTRICHT TELSTAR 1.40 4.00 X 5.25
    324819 31/8 / 2012 DORDRECHT VEENDAM 1.80 3.25 3.45 1
    324834 31/8 / 2012 CEARÁ GUARATINGUETÁ 1.40 3.85 X 5.50

    If this table consists of
    dates
    teams (hometeam, awayteam)
    numbers for homewin, shoot, awaywin probability
    and the final result as 1, X, 2

    What I want is a sql query that returns to me for each hometeam, awayteam and (if possible in a single line)
    all documents of the hometeam which had the same number of prior probability. For example:
    CEARÁ (last line), I would like to the sql to show me all the records of CEARA who had _1.40 3.85 or 5.50_ in each of the three issues of probability, BUT the problem is that I do want separate lines... I can do so far is to calculate a sum of House probability, probability of drawing, close probability for each team but the same records are calculated again in each game of probability!

    This means if CEARÁ has 1.40-3.85-5.50 in the past it will return me this line only once, and not 3 times (one for each set of probability)

    I hope that I've done my duty,
    Thank you for your time and lights
    N. Saridakis

    Is that what you are looking for:

    select hometeam,
           awayteam,
           hw,
           hd,
           hl
    from  (select hometeam,
                  awayteam,
                  ft,
                  SUM(CASE ft
                      WHEN '1' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hw,
                  SUM(CASE ft
                      WHEN 'X' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hd,
                  SUM(CASE ft
                      WHEN '2' THEN 1
                      ELSE 0
                      END) OVER (PARTITION BY hometeam) hl
           from   plays)
    where ft is null
    

Maybe you are looking for