数据库环境
openGauss:2.0.0 - 数据库实训平台
学习笔记
在第17天的课堂代码中,出现了
CURSOR cursor1 FOR SELECT * FROM tpcds.reason ORDER BY 1;
学习中可以用select *,工作中要写全每个字段名。
代码的末尾有个ORDER BY 1,order by是排序的意思,默认是升序,其后的数字指的是按照第n个字段进行排序。
代码演示
omm=# create schema my_schema;
CREATE SCHEMA
omm=# create table my_schema.product
omm-# (
omm(# product_id integer,
omm(# product_name char(30),
omm(# product_count integer
omm(# );
CREATE TABLE
omm=# insert into my_schema.product values(1,'apple',21),(2,'orange',21),(3,'banana',22),(4,'juice',23),(5,'pear',24),(6,'grape',25),(7,'mango',26);
INSERT 0 7
omm=# select * from my_schema.product;
product_id | product_name | product_count
------------+--------------------------------+---------------
1 | apple | 21
2 | orange | 21
3 | banana | 22
4 | juice | 23
5 | pear | 24
6 | grape | 25
7 | mango | 26
(7 rows)
omm=# select product_id,product_name,product_count from my_schema.product order by product_name;
product_id | product_name | product_count
------------+--------------------------------+---------------
1 | apple | 21
3 | banana | 22
6 | grape | 25
4 | juice | 23
7 | mango | 26
2 | orange | 21
5 | pear | 24
(7 rows)
omm=# select product_id,product_name,product_count from my_schema.product order by 2;
product_id | product_name | product_count
------------+--------------------------------+---------------
1 | apple | 21
3 | banana | 22
6 | grape | 25
4 | juice | 23
7 | mango | 26
2 | orange | 21
5 | pear | 24
(7 rows)
参考资料
学习资源
- openGauss SQL学习参考资料
- 每日一练:openGauss数据库在线实训课程
- openGauss每日一练 | 21期养成好习惯,提升技术能力!
- 墨天轮Markdown编辑器使用介绍
- 墨天轮数据库在线实训平台V1.0操作手册
- 墨天轮数据社区
欢迎各位同学一起来交流学习心得!
最后修改时间:2021-12-22 11:54:04
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




