PostgreSQL simple select(group by and insert into ...select)
warehouse_db=# create table student(number int primary key,name varchar(20),age int);
CREATE TABLE
warehouse_db=# insert into student values (1,'David',20);
INSERT 0 1
warehouse_db=# insert into student values (2,'Luna',21);
INSERT 0 1
warehouse_db=# insert into student values (3,'Lisa',21);
INSERT 0 1
warehouse_db=# insert into student values (4,'Susan',22);
INSERT 0 1
warehouse_db=# insert into student values (5,'Jack',22);
INSERT 0 1
warehouse_db=# insert into student values (6,'Peter',23);
INSERT 0 1
warehouse_db=# insert into student values (7,'Andrew',23);
INSERT 0 1
warehouse_db=# insert into student values (8,'Stallman',23);
INSERT 0 1
warehouse_db=# select * from student ;
number | name | age
--------+----------+-----
1 | David | 20
2 | Luna | 21
3 | Lisa | 21
4 | Susan | 22
5 | Jack | 22
6 | Peter | 23
7 | Andrew | 23
8 | Stallman | 23
(8 rows)
分组查询
warehouse_db=# select age,count(*) from student group by age;
age | count
-----+-------
23 | 3
20 | 1
22 | 2
21 | 2
(4 rows)
warehouse_db=# select * from student order by age;
number | name | age
--------+----------+-----
1 | David | 20
2 | Luna | 21
3 | Lisa | 21
4 | Susan | 22
5 | Jack | 22
6 | Peter | 23
7 | Andrew | 23
8 | Stallman | 23
(8 rows)
warehouse_db=# select * from student order by age desc;
number | name | age
--------+----------+-----
8 | Stallman | 23
6 | Peter | 23
7 | Andrew | 23
5 | Jack | 22
4 | Susan | 22
3 | Lisa | 21
2 | Luna | 21
1 | David | 20
(8 rows)
warehouse_db=# select * from student where age <= 22 order by age desc;
number | name | age
--------+-------+-----
4 | Susan | 22
5 | Jack | 22
2 | Luna | 21
3 | Lisa | 21
1 | David | 20
(5 rows)
warehouse_db=# create table student_bak(number int primary key,name varchar(20),age int);
CREATE TABLE
warehouse_db=# insert into student_bak select * from student;
INSERT 0 8
warehouse_db=# select * from student_bak ;
number | name | age
--------+----------+-----
1 | David | 20
2 | Luna | 21
3 | Lisa | 21
4 | Susan | 22
5 | Jack | 22
6 | Peter | 23
7 | Andrew | 23
8 | Stallman | 23
(8 rows)
PostgreSQL simple select(group by and insert into ...select)的更多相关文章
- select into from 和 insert into select 的用法和区别
select into from 和 insert into select都是用来复制表,两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建.insert ...
- select into from和insert into select from两种表复制语句区别
select into from和insert into select from两种表复制语句都是将源表source_table的记录插入到目标表target_table,但两句又有区别. 第一句(s ...
- select into from 和 insert into select 的用法和区别(转)
转自:http://www.studyofnet.com/news/182.html select into from 和 insert into select都是用来复制表,两者的主要区别为: se ...
- 表复制语句select into from 与 insert into select 区别鉴赏
select into from 与 insert into select 区别鉴赏 1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,fi ...
- select into from 和 insert into select 的用法
SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) valu ...
- select into from 和 insert into select
select into from 和 insert into select都是用来复制表, 两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建. inser ...
- select into from 与 insert into select 区别
1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tab ...
- 【oracle】select into from 和 insert into select 的用法和区别
select into from 和 insert into select都是用来复制表,两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建.insert ...
- SELECT INTO FROM 与 INSERT INTO SELECT区别鉴赏
.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tabl ...
随机推荐
- linux 自动登录脚本
#!/usr/bin/expect set port 22 set user xiaoming set password xiaoming123 set host 111.222.22.33 set ...
- 医生加号页改版,就一个Bug, 看医生工作台一期需求
8/8日报 分级埋点: [MobClick event:UmengPagePlusDoctor attributes:@{@"page":@"plusPage&q ...
- 纸牌project
用range[0,8)的列表表示牌,这些数字要出现两次.我们建议你通过连接两个range[0,8)的列表来创建这个list.利用Docs来安排列表串联操作 写一个draw handler啥样的draw ...
- Locking
Computer Science An Overview _J. Glenn Brookshear _11th Edition To solve such problems, a DBMS could ...
- The Producer-Consumer Relationship Version 2
Listing -. The Producer-Consumer Relationship Version public class PC { public static void main(Stri ...
- IE中的fireEvent和webkit中的dispatchEvent
拿浏览器的click事件来说: 在IE浏览器中如果一个element没有注册click事件,那么直接调用的话会出现异常!当然如果你注册了没有什么可说的. 那么如果使用fireEvent来处理,clic ...
- {$ecs_css_path}
includes里的init.php的187-194行 if (!empty($_CFG['stylename'])) { $smarty->assign('ecs_css_path', 'th ...
- 简单计算器--hdu1237(栈的运用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1237 这是单纯的本题答案: #include<stdio.h> #define N 11 ...
- 用代码调用Storyboard里面的viewController
今天在帮助群里的一个朋友弄pop事件,在他那边,当前的viewcontroller,不能pop出去. 初步估计,他的ViewController层级多,他自己没有理清. 因为pushViewContr ...
- 开始了ecshop
一个多星期前开始接触ecshop,突然决定要用它来做网站,于是从网上找各种手册与视频,联系官网客服,然后知道官网一共提供三种类型的服务,一种是ecshop授权,不包含任何技术支持,第二种是易开店的标准 ...