作业题目:
1.创建一个表products
字段名 | 数据类型 | 含义 |
---|---|---|
product_id | INTEGER | 产品编号 |
product_name | Char(30) | 产品名 |
category | Char(20) | 种类 |
2.向表中插入数据,采用一次插入一条和多条记录的方式
product_id | product_name | category |
---|---|---|
1502 | olympus_camera | electrncs |
1601 | lamaze | toys |
1700 | wait_interface | Books |
1666 | harry_potter | toys |
3.查询表中所有记录及记录数
4.查询表中所有category记录,并将查询结果按升序排序
5.查询表中category为toys的记录
6.删除表products
作业操作内容:
root@modb:~# su - omm
omm@modb:~$ gsql -r
gsql ((openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:03:52 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# create table products(product_id integer,^C
omm=# create table products
omm-# (product_id integer,omm(#
product_name char(30),
omm(# category char(20));
CREATE TABLE
omm=# insert into products values(1502,'olympus camera','electrncs');
INSERT 0 1
omm=# insert into products values(1601,'lamaze','toys');
INSERT 0 1
omm=# insert into products values(1700,'wait interface','Books');
INSERT 0 1
omm=# insert into products values(1666,'harry potter','toys');
INSERT 0 1
omm=# select * from products;
product_id | product_name | category
------------+--------------------------------+----------------------
1502 | olympus camera | electrncs
1601 | lamaze | toys
1700 | wait interface | Books
1666 | harry potter | toys
(4 rows)
omm=# select count(*) from products;
count
-------
4
(1 row)
omm=# select * from products order by category;
product_id | product_name | category
------------+--------------------------------+----------------------
1700 | wait interface | Books
1502 | olympus camera | electrncs
1601 | lamaze | toys
1666 | harry potter | toys
(4 rows)
omm=# select * from products where category='toys';
product_id | product_name | category
------------+--------------------------------+----------------------
1601 | lamaze | toys
1666 | harry potter | toys
(2 rows)
omm=# drop table products;
DROP TABLE