暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第 1 天

原创 刘志亮 2021-12-01
573

openGauss每日一练第 1 天

如何登录数据库

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 (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');
复制


查询数据

select count(*) from customer_t;

select * from customer_t;

select c_first_name from customer_t;
复制


数据去重

SELECT DISTINCT(c_first_name) from customer_t;

SELECT c_first_name from customer_t group by c_first_name  ;
复制


删除表

drodrop table customer_t;
复制


openGauss每日一练第 1 天作业

1.创建一个表products

create table products (product_id INTEGER,product_name Char(10),category Char(10));
复制



2.向表中插入数据,采用一次插入一条和多条记录的方式

INSERT INTO products (product_id ,product_name ,category)  VALUES  (1502,'olympus camera','electrncs');

INSERT INTO products (product_id ,product_name ,category) VALUES 
(1601, 'lamaze' ,'toys'),
(1700, 'waitinterface' ,'Books'),
(1666, 'harry potter', 'toys');
复制



注: 插入数据时候会报字段长度不够,所以要修改一下表的字段长度。

修改表的字段长度 alter table products alter COLUMN product_name type char(20);


3.查询表中所有记录及记录数

select count(*) from products ;

select * from products ;
复制



4.查询表中所有category记录,并将查询结果按升序排序

select category from  products order by category  ;
复制



5.查询表中category为toys的记录

select * from products  where category ='toys';
复制



6.删除表products

drop table products  ;
复制



第一天简单的了解了一下opengauss的表相关操作,希望后面有更多惊喜。


最后修改时间:2021-12-02 10:00:26
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论