Select result, and only show if all are equivalent

0

I'm servicing a database, and I have the following situation; in the database I have 5 columns in a table, they are:

  

ID (PK) | IDBillet | Result | Borrowed | Date |

I have to filter for the user to see, only the IDBilhete that is missing result, or that already has the results all checked.

Usually use select * from bilhetes to return everything, and something like this comes up:

  

00 | BFF554 | 0 | 0 | 12/21/2017

     

01 | BFF554 | 1 | 0 | 12/21/2017

     

02 | BFF554 | 2 | 0 | 12/21/2017

     

03 | CCC154 | 1 | 0 | 12/22/2017

     

04 | CCC154 | 3 | 0 | 12/22/2017

     

05 | CCC154 | 1 | 0 | 12/22/2017

So I want to group the repeated IDBillages only if all the 'result' columns of this ID are equal to a specific value.

Ex: Return the IDBillet only if all 'result' columns equal 0! So if BFF554 has all 3 columns result with value 0, the query returns me that ID, if one of the result columns is not 0, then that ID does not interest me.

    
asked by anonymous 01.02.2018 / 15:34

1 answer

1

select bi. *    from    bi where tickets       bi.IDBilhete not in (                        select b.IDBilhete from tickets as b Where                        Result > 0                        )  group by bi.IDBilhete

You first strip the idbbles that have resulted in more than zero, and then you group the rest.

    
01.02.2018 / 16:24