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)的更多相关文章

  1. select into from 和 insert into select 的用法和区别

    select into from 和 insert into select都是用来复制表,两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建.insert ...

  2. select into from和insert into select from两种表复制语句区别

    select into from和insert into select from两种表复制语句都是将源表source_table的记录插入到目标表target_table,但两句又有区别. 第一句(s ...

  3. select into from 和 insert into select 的用法和区别(转)

    转自:http://www.studyofnet.com/news/182.html select into from 和 insert into select都是用来复制表,两者的主要区别为: se ...

  4. 表复制语句select into from 与 insert into select 区别鉴赏

    select into from 与 insert into select 区别鉴赏 1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,fi ...

  5. select into from 和 insert into select 的用法

    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) valu ...

  6. select into from 和 insert into select

    select into from 和 insert into select都是用来复制表, 两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建. inser ...

  7. select into from 与 insert into select 区别

    1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tab ...

  8. 【oracle】select into from 和 insert into select 的用法和区别

    select into from 和 insert into select都是用来复制表,两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建.insert ...

  9. SELECT INTO FROM 与 INSERT INTO SELECT区别鉴赏

    .INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tabl ...

随机推荐

  1. UCenter 通信失败 和 无法同步登陆的调试方法

    1. 看请求 2./uc_server/control/admin/app.php echo "\$url = $url <br />\n \$status = $status& ...

  2. javaWeb中struts开发——Logic标签

    1.Struts标签的logic标签 Logic标签是逻辑标签,是Struts中比较重要的标签,完成各种逻辑运算操作,可以直接支持全局调转. 2.1<logic:present><l ...

  3. 线性表集合A=A B

    大话数据结构 void union(List *a, List Lb) { int La_len, Lb_len, i; ElemType e; La_len = ListLength(La); Lb ...

  4. c语言main函数返回值、参数详解(返回值是必须的,0表示正常退出)

    C语言Main函数返回值 main函数的返回值,用于说明程序的退出状态.如果返回0,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...

  5. MAGENTO程序结构图

    Magento程序结构图(Program Structure Diagram): /app – 程序根目录 /app/etc – 全局配置文件目录 /app/code – 所有模块安装其模型和控制器的 ...

  6. Selenium2学习-030-WebUI自动化实战实例-028-获取元素位置及大小

    自动化测试过程中,有时需要获取元素的位置.大小,以获取元素的位置,通过 Actions 模拟鼠标,进行相对坐标操作.例如,有些元素定位不方便,或者需要对某一元素相对区域范围进行暴力点击测试,此时就需要 ...

  7. Selenium2学习-027-WebUI自动化实战实例-025-JavaScript 在 Selenium 自动化中的应用实例之三(页面滚屏,模拟鼠标拖动滚动条)

    日常的 Web UI 自动化测试过程中,get 或 navigate 到指定的页面后,若想截图的元素或者指定区域范围不在浏览器的显示区域内,则通过截屏则无法获取相应的信息,反而浪费了无畏的图片服务器资 ...

  8. php常用转义字符‘ “ {} $ \n

    php 单引号和双引号的区别: 双引号串中的内容可以被解释而且替换,而单引号串中的内容总被认为是普通字符. <?php $a = 'abc'; echo "<br>&quo ...

  9. js基础的总结

    js中的每个函数都含有一个内建的arguments数组,能够返回函数接受的所有参数,不管函数有没有定义参数. function add() { var sum = 0; for (var i = 0; ...

  10. ChatForFun 公众号使用说明

    使用方法 2016-07-16 DennisMi ChatForFun 1,发送  #1 实现登陆,或者退出登陆 2,发送  #2 实现加入聊天,和退出聊天 3,聊天开始后,可以直接发送消息 4,如果 ...