4

目标

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

问题

我不知道语法。

场景

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

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

上下文是:市场产品。产品属于市场。如果某个市场暂停,则不会显示其产品,也不会将它们添加到最大/最小价格比较中。

大家能看懂吗?我想从上述查询的or语句中排除其市场被暂停的产品。MinMax

桌子

这是markets表格:

+----+------+-------------+
| Id | Name | SituationId |
+----+------+-------------+
| 1  | A    | 1           |
+----+------+-------------+
| 2  | B    | 2           |
+----+------+-------------+
| 3  | C    | 3           |
+----+------+-------------+

这是markets_situations表格:

+----+-----------+
| Id | Name      |
+----+-----------+
| 1  | Neutral   |
+----+-----------+
| 2  | Premium   |
+----+-----------+
| 3  | Suspended |
+----+-----------+

最后,这是products表格:

+----+---------------+--------+------------------+---------------+
| 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        |
+----+---------------+--------+------------------+---------------+

为了提高理解力

我不想显示110,00Min存储过程结果的价格,因为它的市场 ( C) 是Suspended.

我已经做过的

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

BEGIN
    [...]

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

发生什么了?And条件什么也不做。该查询不断向我返回暂停市场的价格。

4

2 回答 2

1
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';
于 2013-09-03T16:59:49.320 回答
0

像这样的东西怎么样

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
于 2013-09-03T16:59:27.240 回答