Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如果出现以下情况,请不要返回最低值 目标_Mysql_Sql - Fatal编程技术网

Mysql 如果出现以下情况,请不要返回最低值 目标

Mysql 如果出现以下情况,请不要返回最低值 目标,mysql,sql,Mysql,Sql,不要返回其市场暂停的最低价格 问题 我不知道语法 情景 有以下存储过程可获取特定产品的最低和最高价格: BEGIN Select Min(Case When product.PromotionalPrice = 0 Then product.OriginalPrice Else Least(product.PromotionalPrice, product.OriginalPrice) End) As minProd

不要返回其市场暂停的最低价格

问题 我不知道语法

情景 有以下存储过程可获取特定产品的最低和最高价格:

BEGIN
    Select Min(Case When product.PromotionalPrice = 0
            Then product.OriginalPrice Else
            Least(product.PromotionalPrice, product.OriginalPrice)
            End) As minProductPrice,
       Max(Case When product.PromotionalPrice = 0
            Then product.OriginalPrice Else
            Least(product.PromotionalPrice, product.OriginalPrice)
            End) As maxProductPrice
    From products As product
    Where product.Name = 'Playstation 3';
END
背景是:有市场和产品。产品属于市场。如果某个市场暂停,则不会显示其产品,也不会将其添加到最大/最小价格比较中

你们都能理解吗?我想从上述查询的Min或Max语句中排除其市场被暂停的产品

桌子 以下是市场表:

以下是市场情况表:

最后,这里是产品表:

提高理解力 我不想显示110,00作为存储过程结果的最小价格,因为它的市场C已暂停

我已经做了什么 我已经尝试了以下方法,但没有成功:

BEGIN
    [...]

    Where product.Name = 'Playstation 3'
    And marketSituation.Id <> 3;
END

会发生什么?而条件不起任何作用。查询不断向我返回暂停市场的价格。

类似的情况如何

Select Min(Case When product.PromotionalPrice = 0
        Then product.OriginalPrice Else
        Least(product.PromotionalPrice, product.OriginalPrice)
        End) As minProductPrice,
   Max(Case When product.PromotionalPrice = 0
        Then product.OriginalPrice Else
        Least(product.PromotionalPrice, product.OriginalPrice)
        End) As maxProductPrice
From products As product INNER JOIN
Markets ON Product.Market = Markets.Id
Where product.Name = 'Playstation 3'
AND Markets.SituationID <> 3

因此,加入情境表,然后让where markets_情境3过滤掉暂停的情境。+问题:我不知道语法。哈哈,我已经这么做了,@MarcB。但是这个查询不断返回110,00.00,效果非常好。谢谢,法比恩=
+----+---------------+--------+------------------+---------------+
| Id | Name          | Market | PromotionalPrice | OriginalPrice |
+----+---------------+--------+------------------+---------------+
| 1  | Xbox 360      | 1      | 0                | 225,00        |
+----+---------------+--------+------------------+---------------+
| 2  | Xbox 360      | 2      | 99,00            | 175,00        |
+----+---------------+--------+------------------+---------------+
| 3  | Xbox 360      | 3      | 0                | 135,00        |
+----+---------------+--------+------------------+---------------+
| 4  | Playstation 3 | 1      | 0                | 189,00        |
+----+---------------+--------+------------------+---------------+
| 5  | Playstation 3 | 2      | 125,00           | 165,00        |
+----+---------------+--------+------------------+---------------+
| 6  | Playstation 3 | 3      | 110,00           | 185,00        |
+----+---------------+--------+------------------+---------------+
BEGIN
    [...]

    Where product.Name = 'Playstation 3'
    And marketSituation.Id <> 3;
END
Select Min(Case When product.PromotionalPrice = 0
        Then product.OriginalPrice Else
        Least(product.PromotionalPrice, product.OriginalPrice)
        End) As minProductPrice,
   Max(Case When product.PromotionalPrice = 0
        Then product.OriginalPrice Else
        Least(product.PromotionalPrice, product.OriginalPrice)
        End) As maxProductPrice
From products As product INNER JOIN
Markets ON Product.Market = Markets.Id
Where product.Name = 'Playstation 3'
AND Markets.SituationID <> 3
Select Min(Case When product.PromotionalPrice = 0
        Then product.OriginalPrice Else
        Least(product.PromotionalPrice, product.OriginalPrice)
        End) As minProductPrice,
   Max(Case When product.PromotionalPrice = 0
        Then product.OriginalPrice Else
        Least(product.PromotionalPrice, product.OriginalPrice)
        End) As maxProductPrice
From products As product
Inner join markets on product.market = markets.id AND markets.SituationId <> 3
Where product.Name = 'Playstation 3';