sql >> Databasteknik >  >> RDS >> Sqlserver

SQL VÄLJ flera villkor många till många relation

SELECT p2p.PageID
FROM
    PageToProduct as p2p
    inner join Product as pr
        on p2p.Product = pr.Product
    inner join PageToProductToRate as p2p2r
        on p2p2r.PageToProductID = p2p.PageToProductID
    inner join ProductRates as r
        on r.ProductRatesID = p2p2r.ProductRatesID 
WHERE
          (pr.Product = 'ALMOND' AND r.CommissionType = 'PREMIUM' AND r.Rate = 0.25) 
      OR  (pr.Product = 'WALNUT' AND r.CommissionType = 'SERVICE FEE' AND r.Rate = 1.25)
      OR  (pr.Product = 'HAZELNUT' AND r.CommissionType = 'EXCESS' AND r.Rate = 1.68)
GROUP BY p2p.PageID
HAVING COUNT(*) = 3; /* requires all three are present, as long as no rows are duplicate */


  1. ORACLE Sök i alla tabeller i en sträng med BLOB-kolumn

  2. Inaktivera CAST AS för att optimera frågan i Entity Framework

  3. Hur man hanterar MariaDB 10.3 med ClusterControl

  4. Hur POSITION()-funktionen fungerar i MySQL