首页 > 其他 > 详细

postgres —— 零碎笔记

时间:2019-10-01 23:30:14      阅读:121      评论:0      收藏:0      [点我收藏+]

聚合函数

-- 聚合查询
SELECT city, max(temp_lo)
FROM weather
WHERE city LIKE ‘S%‘
GROUP BY city
HAVING max(temp_lo) < 40; -- HAVING 子句始终包含聚合函数, 否则没有意义

 

更新语句

-- 更新语句
UPDATE weather
    SET temp_hi = temp_hi - 2,  temp_lo = temp_lo - 2
    WHERE date > ‘1994-11-28‘;

 

事务

-- 事务
BEGIN;
UPDATE accounts SET balance = balance - 100.00
    WHERE name = ‘Alice‘;
SAVEPOINT my_savepoint;
UPDATE accounts SET balance = balance + 100.00
    WHERE name = ‘Bob‘;
-- oops ... forget that and use Wally‘s account
ROLLBACK TO my_savepoint;
UPDATE accounts SET balance = balance + 100.00
    WHERE name = ‘Wally‘;
COMMIT;

  

233

postgres —— 零碎笔记

原文:https://www.cnblogs.com/lemos/p/11616398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!