我正在努力尝试在一列中根据列中的值在'select'语句中创建3个单独列的查询。SQL查询将列表转换为多列
我的例子:
我有两个表
forest.plots
columns = id(PK), a, b
forest.plot_measurements
columns = id(PK), plot_id (FK), measure_type (int), value_real
当plot_measurement具有measure_type = 1,这是一个斜率测量,如果measure_type = 2,则它是一个wet_weight量度
的期望的结果将是具有标题的表格:
plot_id, slope, wet_weight
我想斜率柱从value_real包含值,其中measure_type = 2,我希望wet_weight柱从value_real包含值,其中measure_type = 1
我只有代码成功在获得的一个值:
select pm.value_real slope, pl.input_plot_id
from forest.plot_measurement pm
inner join forest.plots pl on pm.plot_id = pl.plot_id
where pm.plot_measurement_type_id = 1
如何获得第二个测量列?任何帮助不胜感激。
贝基
太好了,非常感谢。不是每一行都有湿重和坡度的测量值,所以后面的选项是合适的。 ...我注意到,虽然这需要一段时间来查询(一次我添加了其他几种类型的测量)。谢谢 – user3770062 2014-12-04 08:11:45