开心一笑
妻子:“哎,快到站了,有零钱吗?”
丈夫大惑不解:“你忘性真大。自打和你认识起,我袋里就从来没有过整张的!”
提出问题
with语句的用法!!!
解决问题
with语句,可以被看作是定义临时表的存在
数据准备
创建表ay_tree_test:
CREATE TABLE ay_tree_test
(
id character varying(3),
pid character varying(3),
name character varying(10)
)
插入数据:
INSERT INTO ay_tree_test values('001','0','厦门市');
INSERT INTO ay_tree_test values('002','001','海沧区','2100');
INSERT INTO ay_tree_test values('003','001','集美区','2500');
INSERT INTO ay_tree_test values('004','001','同安区','1500');
INSERT INTO ay_tree_test values('005','002','区政府','1');
INSERT INTO ay_tree_test values('006','002','青春海岸','10');
INSERT INTO ay_tree_test values('007','002','未来海岸','15');
语法:
在with查询的基本语法如下:
WITH
name_for_summary_data AS (
SELECT Statement)
SELECT columns
FROM name_for_summary_data
WHERE conditions <=> (
SELECT column
FROM name_for_summary_data)
[ORDER BY columns]
例子:
with t as(
select id,name,pid from ay_tree_test2 where pid = '001'
)
select * from
结果如下:
例二:
WITH t AS (
UPDATE ay_tree_test2 SET price = price * 1.05
RETURNING *
)
SELECT * FROM t;
结果:with语句和update组合
读书感悟
- 戴尔·卡耐基曾说:“专业知识在一个人成功中的作用只占15%,其余的85%则取决于人际关系。
- 笑得再“真诚”,眼睛也会出卖他
- 人的情绪发生变化时,面部表情也许能够通过意志力的手段来控制,从而做到喜怒不形于色
说话的时候,就算是言不由衷,也可以说得坦然逼真,可是唯有眼睛很难说谎,因为通常眼睛显示的是大脑的真实活动。