SQL:用3个不同的where子句查询同一列3次
SQL: Query the same column 3 times with 3 different where clauses
正在尝试显示一个 table,其中有 3 列是需要显示的价格。这些列由 'price_type' 区分,并且有 3 种不同的价格类型。
这可能是我明显遗漏的东西,但类似于:
Select price as 'current', price as '10min', price as '30min'
from table
where Price_Type(current) = 'current' AND Price_Type(10min) = '10min' AND
Price_Type(30min) = '30min'
Order by date desc
我不确定实际语法是什么,但如有任何帮助,我们将不胜感激。
有条件聚合:
select date,
max(case when Price_Type = 'current' then price end) as [current],
max(case when Price_Type = '10min' then price end) as [10min],
max(case when Price_Type = '30min' then price end) as [30min]
from table
group by date
order by date desc
正在尝试显示一个 table,其中有 3 列是需要显示的价格。这些列由 'price_type' 区分,并且有 3 种不同的价格类型。
这可能是我明显遗漏的东西,但类似于:
Select price as 'current', price as '10min', price as '30min'
from table
where Price_Type(current) = 'current' AND Price_Type(10min) = '10min' AND
Price_Type(30min) = '30min'
Order by date desc
我不确定实际语法是什么,但如有任何帮助,我们将不胜感激。
有条件聚合:
select date,
max(case when Price_Type = 'current' then price end) as [current],
max(case when Price_Type = '10min' then price end) as [10min],
max(case when Price_Type = '30min' then price end) as [30min]
from table
group by date
order by date desc