Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 少数列上的Postgres max_Sql_Postgresql_Max_Aggregate Functions - Fatal编程技术网

Sql 少数列上的Postgres max

Sql 少数列上的Postgres max,sql,postgresql,max,aggregate-functions,Sql,Postgresql,Max,Aggregate Functions,我有一张桌子,看起来像这样 id | item | price1 | price2 我想得到物品清单,对于每一件物品,我还想在价格1和价格2中选择最高价格。可以在一个查询中完成吗?差不多 SELECT item, max(price1,price2) FROM table; 更新 例如: 表包含 item1 | 4 | 8 item2 | 5 | 1 item3 | 7 | 7 我希望结果是 item1 | 8 item2 | 5 item3 | 7 使用: 你能举例说明你期望结果是什

我有一张桌子,看起来像这样

 id | item | price1 | price2
我想得到物品清单,对于每一件物品,我还想在价格1和价格2中选择最高价格。可以在一个查询中完成吗?差不多

SELECT item, max(price1,price2) FROM table;
更新

例如:

表包含

item1 | 4 | 8
item2 | 5 | 1
item3 | 7 | 7
我希望结果是

item1 | 8
item2 | 5
item3 | 7
使用:


你能举例说明你期望结果是什么样的吗?使用max(price1)、max(price2)、group by和case语句选择两者中较大的一个作为最终输出信号
SELECT GREATEST(1, 100);
┌──────────┐
│ greatest │
├──────────┤
│      100 │
└──────────┘
(1 row)