在AND之间使用不同列之间的OR

时间:2016-04-13 04:15:58

标签: mysql

我有一个mysql查询

 timeout = setTimeout(2000,funciton(){
            //after 2sec starts
            $(this).attr("data-price",dInput);
            shoppingCart.setPriceForItem(dInput,id);
            displayCart();
            //after 2sec ends
});

可以看出,它只允许那些具有$query = "SELECT id,link, shape, size, color, clarity, cut, price, markup, cert, certificateNumber, stockNumber FROM diamonds WHERE cert IN ('GIA,AGS') AND storeKey = '$storeKey' AND size BETWEEN $minCarat AND $maxCarat AND price BETWEEN $minPrice AND $maxPrice AND cut IN($cut) AND clarity IN ($clarity) AND color IN ($color) AND shape IN ($shape) ORDER BY price ASC";

的钻石列表

我想添加另一个条件。该表有一列"链接"它可以是空的也可以是非空的。如果我使用GIA或AGS,许多钻石将被排除在外,这些钻石的链接不是空的。我也想为链接添加条件。像

这样的东西
cert Either GIA Or AGS

除了AND和其他值之外,我如何添加或

1 个答案:

答案 0 :(得分:0)

$query = "SELECT 
           id,link,shape,size,
           color, clarity, cut, price,
           markup, cert, certificateNumber,stockNumber
         FROM 
            diamonds 
        WHERE 
              (cert IN ('GIA,AGS') or link != '')
          AND storeKey = '$storeKey'
          AND size BETWEEN $minCarat AND $maxCarat
          AND price BETWEEN $minPrice AND $maxPrice 
          AND cut IN($cut)
          AND clarity IN ($clarity)
          AND color IN ($color)
          AND shape IN ($shape)
       ORDER BY price";

仅添加OR声明

,看不出任何问题