减去相同 Table 的价格
Subtract price on same Table
我有一个 table,下面是列名称。我想找到 MAX(NewyorkPrice-MANITOBAPrice,0)
的结果
IntertieZoneName DeliveryHour Price
MANITOBA 1 16.2
MANITOBA 2 19.0
NEWYORK 1 14.4
NEWYORK 2 20.0
的预期输出
Price DeliveryHour
0 1
1.0 2
请帮我写Sql关于自己的查询Table
SELECT CASE WHEN t.price_difference < 0 THEN 0 ELSE t.price_difference END AS Price,
t.DeliveryHour
FROM
(
SELECT DeliveryHour,
MAX(CASE WHEN IntertieZoneName = 'NEWYORK' THEN Price END) -
MAX(CASE WHEN IntertieZoneName = 'MANITOBA' THEN Price END) AS price_difference
FROM yourTable
GROUP BY DeliveryHour
) t
我有一个 table,下面是列名称。我想找到 MAX(NewyorkPrice-MANITOBAPrice,0)
的结果IntertieZoneName DeliveryHour Price
MANITOBA 1 16.2
MANITOBA 2 19.0
NEWYORK 1 14.4
NEWYORK 2 20.0
的预期输出
Price DeliveryHour
0 1
1.0 2
请帮我写Sql关于自己的查询Table
SELECT CASE WHEN t.price_difference < 0 THEN 0 ELSE t.price_difference END AS Price,
t.DeliveryHour
FROM
(
SELECT DeliveryHour,
MAX(CASE WHEN IntertieZoneName = 'NEWYORK' THEN Price END) -
MAX(CASE WHEN IntertieZoneName = 'MANITOBA' THEN Price END) AS price_difference
FROM yourTable
GROUP BY DeliveryHour
) t