Home > Mobile >  How can I create a SQL Query that pulls a flag when the price quantity is 10? I am using Microsoft S
How can I create a SQL Query that pulls a flag when the price quantity is 10? I am using Microsoft S

Time:06-03

FAIL FLAG

What they want is getting the average price from the Price and Price Quantity column (price/pricequantity), and marking the difference. If the price quantity doesn't match all 6 locations, then the flag is a Fail, If the price quantity match all 6 locations, then the flag is a Pass.

PASS FLAG

CodePudding user response:

In SQL use CASE WHEN

   SELECT *, CASE 
           WHEN PriceQuantity = 10 THEN 'true'
           ELSE 'false'
    END AS Flag
    FROM table

CodePudding user response:

Sorry the question was different. It is the same method to apply but with the calculation :

SELECT *, 
    CASE 
      WHEN ((Price/Qyt) = AVG(Price/Qyt)) THEN 'true'
      ELSE 'false'
    END AS Flag
FROM table
GROUP BY Item, Site, Date, Price, ... (and others column but not Flag) 
  • Related