我想将同一项目的类型更改为相同。例如,我的表如下所示:
public function connection()
{
//connection
$ssh = new SSH2('10.10.10.10');
if (!$ssh->login('login', 'passwrd'))
{
exit('Login Failed');
}
//chmod command
echo $ssh->exec('sudo chmod -R 775 test_folder');
}
所需的输出:
$ssh->disconnect();
答案 0 :(得分:1)
您可以将值设置为最小:
update t
set t.type = t2.min_type
from (select t2.item, min(type) as min_type
from t t2
group by t2.item
) t2;
如果您有指定顺序的列,则可以将其表达为:
update t
set t.type = t2.type
from (select distinct on (t2.item) t2.item, t2.type
from t t2
order by t2.item, t2.?
) t2;
SQL表表示无序集。除非某列专门包含此信息,否则没有“第一”行。