SQL: WHERE clause of multiple criteria

SELECT
    ((1.0 * (SELECT SUM(r.SalesVolume) 
             FROM RawData r
             INNER JOIN Product p ON r.ProductId = p.ProductId
             WHERE p.Distributor = 'TF1', 'WARNER')
GROUP BY p.Distributor)
/
(SELECT SUM(r.SalesVolume) FROM RawData r)*100)
;

      

The above query gives an error:

Lookup Error - SQL Server Database Error: Incorrect syntax near ','.

      

Can anyone point out what the problem is? I know that I cannot use the OR / AND condition in this case. The result set must have 2 rows.

Product:

Distributor     
  WARNER              
  TF1                 
  WARNER              
  TF1  

      

RAWDATA:

   SalesVolume
        5
        6
        3
        4

      

+3


source to share


2 answers


maybe IN

instead of=



SELECT
((1.0*(SELECT SUM(r.SalesVolume) FROM RawData r
INNER JOIN Product p
ON r.ProductId = p.ProductId
WHERE p.Distributor in ('TF1','WARNER'))
/
(SELECT SUM(r.SalesVolume) FROM RawData r)*100)
;

      

+2


source


You must use



WHERE p.Distributor IN ('TF1','WARNER')

      

+1


source







All Articles