Select records under multiple conditions

0

Help in the code to select in MySQL. The conditions are:

  • for records of the same 'net' and 'time', select the first record (id min) and another record if the 'AP' is different
  • For different 'time' and 'net' records, the above condition is used for each group of the same 'net'
  • Example

      

    for time 00:13:56 select records 38 and 40 (net = 11)   for time 00:13:56 select records 42 and 43 (net = 80)   for time 07:30:21 select records 46 and 48 (net = 11)   for time 07:30:21 select record 50 (net = 30)

    Table Data

    id  net   hora     AP
    38  11  00:13:56    4
    39  11  00:13:56    4
    40  11  00:13:56    1
    41  11  00:13:56    4
    42  80  00:13:56    5
    43  80  00:13:56    2
    44  80  00:13:56    5
    45  80  00:13:56    5
    46  11  07:30:21    4
    47  11  07:30:21    4
    48  11  07:30:21    3
    49  11  07:30:21    4
    50  30  07:30:21    1
    
        
    asked by anonymous 18.07.2017 / 22:37

    1 answer

    0

    Use GROUP BY to group records by fields net , hora and AP :

    SELECT MIN(id) FROM tabela GROUP BY net, hora, AP
    
        
    18.07.2017 / 22:58