Skip to content
Advertisement

Create SQL statement with mulitple AND

I have a problem with creating right SQL request. This is my table:

I would like to display all items that:

  1. -Are in warehouse A in number less than 2
  2. -Are in watehouse B in number grater than 0 At the same time.

I would expect item1 will be displayed.

My code so far is:

I know that warehouse = B AND warehouse = A will never happened, but i do not have any idea where to go from here.

I’am new to SQL, but i have feeling that i need to use GRUPBY

Any help ?

Advertisement

Answer

You can use aggregation. Use where to get either condition. Then check that both are met. Assuming that there is one row per item per warehouse, you can use:

Note that this does not return the amounts. If you want that as well, then pivot the data using conditional aggregation:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement