1. 墨天轮实验环境初探:
实训环境是虚拟机 + 文字, 这种方式学习很好,比视频更容易沉浸。
2. 摩天轮文章写作:
采用markdown形式很容易排版,整体网站非常不错。
3. 实验内容
- 切换用户 omm
- 连接数据库 gsql直接连上5432端口
# -r if this parameter is set,use libedit
gsql - r
- 开始创建表
CREATE TABLE customer_t
( c_customer_sk integer,
c_customer_id char(5),
c_first_name char(6),
c_last_name char(8)
) ;
INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES (3769, 5, 'Grace','White');
INSERT INTO customer_t VALUES (3769, 5, 'Grace','White');
INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES
(6885, 1, 'Joes', 'Hunter'),
(4321, 2, 'Lily','Carter'),
(9527, 3, 'James', 'Cook'),
(9500, 4, 'Lucy', 'Baker');
在实验中有时候会出现吞字符的情况,在文档的时候就把代码写出来我觉得是一个比较好的选择
- 查询
omm=# select * from customer_t;
c_customer_sk | c_customer_id | c_first_name | c_last_nam
e
---------------+---------------+--------------+-----------
--
3769 | 5 | Grace | White
3769 | 5 | Grace | White
6885 | 1 | Joes | Hunter
4321 | 2 | Lily | Carter
9527 | 3 | James | Cook
9500 | 4 | Lucy | Baker
(6 rows)
因为没有设置主键,所以有重复记录。
omm=# select c_first_name, count(*) count from customer_t group by c_first_name;
c_first_name | count
--------------+-------
James | 1
Grace | 2
Lucy | 1
Joes | 1
Lily | 1
(5 rows)
4. 课后作业
create table products
(product_id integer,
product_name char(30),
category char(20)
);
insert into products values (1520, 'olympus camera' , 'electrncs');
insert into products values
(1601, 'lamaze', 'toys'),
(1700, 'wait interface', 'Books'),
(1666, 'harry potter', 'toys');
select * from products;
select count(*) from products;
select category from products order by category ASC;
select * from products where category='toys';
drop table products;
5. 结果
omm=# select * from products;
product_id | product_name | categ
ory
------------+--------------------------------+------------
----------
1520 | 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 category from products order by category ASC;
category
----------------------
Books
electrncs
toys
toys
(4 rows)
omm=# select * from products where category='toys';
product_id | product_name | categ
ory
------------+--------------------------------+------------
----------
1601 | lamaze | toys
1666 | harry potter | toys
(2 rows)
完成课时1~
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




