SQL:使用3个不同的where子句查询同一列3次

SQL:使用3个不同的where子句查询同一列3次,sql,tsql,Sql,Tsql,正在尝试显示包含3列的表,这些列是需要显示的价格。这些列按“价格类型”区分,有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

正在尝试显示包含3列的表,这些列是需要显示的价格。这些列按“价格类型”区分,有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

欢迎来到堆栈溢出。拿着这本书通读一遍。阅读此文,然后用示例数据、表格结构和期望的结果回答您的问题,以帮助我们帮助您。天哪,您是一个救生员。非常感谢!!