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 ...
随机推荐
- thinkphp 设计思想
thinkphp 运行机制: thinkphp首先设置一些常量.然后运行Think对象(系统环境),装载think的运行环境,包括:自动加载.异常处理.功能核心等.环境准备好后,运行App对象(应用程 ...
- The world beyond batch: Streaming 101
https://www.oreilly.com/ideas/the-world-beyond-batch-streaming-101 https://www.oreilly.com/ideas/the ...
- 【mysql的紧急应用】
1. 字符串替换 今天老板说要将商品表title中的"AAA"全部改成"BBB",于是乎,百度得到答案. UPDATE goods set title=REPL ...
- [转]C#之反射
前言 之所以要写这篇关于C#反射的随笔,起因有两个: 第一个是自己开发的网站需要用到 其次就是没看到这方面比较好的文章. 所以下定决心自己写一篇,废话不多说开始进入正题. 前期准备 在VS20 ...
- [转]正则表达式相关:C# 抓取网页类(获取网页中所有信息)
using System; using System.Data; using System.Configuration; using System.Net; using System.IO; usin ...
- 关于使用注解出现BeanCreationException或者NameNotFoundException的解决方法
网上大部分解决方法是修改配置文件,但是本人修改后发现还是报错,只能耐着头皮继续看下去,最后发现是path出错,注意web.xml中的<resource-ref>的<res-ref-n ...
- 在HCI层ACL Connection的建立
一.概述 上一篇博文介绍的是inquiry的整个过程中HCI层的command和event.在寻找到有效的远端蓝牙设备后,开始建立ACL连接,这里仅仅反应HCI层的数据包,对于LM层和Base ...
- qt cef嵌入web
原文http://blog.sina.com.cn/s/blog_9e59cf590102vnfc.html 最近项目需要,研究了下libcef库. Cef(Chromium Embedded Fra ...
- MANIFEST.MF详解(转)
转载自http://blog.csdn.net/zhifeiyu2008/article/details/8829637 打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录, ...
- C# 时间与时间戳互转 13位
/// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="t ...