0

我有这个大查询,我只需要过滤掉tbl_dealinterest.Active =的任何结果'n'。有时该表中没有该产品的条目,有时可能存在条目并设置为 y。

这是一个丑陋的大查询:

SELECT tbl_product.id, tbl_productspecification.id AS specificationId,
                        tbl_product.ProductId, tbl_seller.CompanyName, tbl_product.ProductName, tbl_product.Description, mst_Categories.id AS 'Category',
                        tbl_productspecification.RetailPrice, tbl_productspecification.SalePrice,
                        tbl_product.image, tbl_productspecification.Discount, tbl_product.EndTime, tbl_product.Seller_Id, tbl_dealinterest.Active AS thumbsActive
                        FROM tbl_product
                        LEFT OUTER JOIN tbl_seller ON tbl_seller.SelId = tbl_product.Seller_Id
                        LEFT OUTER JOIN mst_Categories ON (mst_Categories.id = tbl_product.Category OR mst_Categories.id = tbl_product.SubCategory)
                        LEFT OUTER JOIN tbl_productspecification ON tbl_productspecification.ProductId = tbl_product.ProductId
                        LEFT OUTER JOIN mst_image ON mst_image.Product = tbl_product.ProductId
                        LEFT OUTER JOIN tbl_dealinterest ON tbl_dealinterest.ProductId = tbl_product.ProductId AND tbl_dealinterest.BuyerId = '$token' 
                        WHERE tbl_product.Active='y'
                        AND tbl_product.StartTime <= '".date("Y-m-d H:i:s")."'
                        AND tbl_product.EndTime > '".date("Y-m-d")." 06:00:00'
                        ".$subquery."
                        GROUP BY tbl_productspecification.ProductId";

感谢您的任何建议。

4

2 回答 2

1
LEFT OUTER JOIN tbl_dealinterest ON (tbl_dealinterest.ProductId = tbl_product.ProductId 
    AND tbl_dealinterest.BuyerId = '$token' 
    AND tbl_dealinterest.Active<>'n')
于 2012-11-24T19:01:47.530 回答
1
SELECT ...
WHERE tbl_product.Active='y'
AND (tbl_dealinterest.Active <> 'n' OR tbl_dealinterest.Active IS NULL)
...
于 2012-11-24T19:17:49.330 回答