MogDB 使用样本数据集Mogila
MogDB 使用样本数据集 Mogila
MogDB 提供了一个样本数据集 Mogila,本数据集借鉴了适用于 MySQL 的Sakila 示例数据库。Sakila最初由 MySQL AB 文档团队的 Mike Hillyer 开发,其目的是提供一个可用于书籍、教程、文章、样本等示例的标准 schema。
Mogila 数据集是一个关于 DVD 出租店信息的数据库,包含有关电影(如标题、类别、女演员)、出租店(如地址、工作人员、客户)和出租的信息。您可以使用 Mogila 数据库进行各种功能测试。
Mogila 适用于 MogDB 2.1 及更高版本。
实体-关系模型图
下图展示了 Mogila 数据库表和视图的概览。您可以查看不同表之间如何通过各个字段相互关联。例如,film表具有title和description列。它还通过列language_id和original_language_id与language表相关联。因此您可以联结这两个表来获取每部电影的语言,或者列出特定语言的所有电影。
在 MogDB 容器版中使用 Mogila
MogDB 容器版本已经内置了 Mogila 样本数据库,无需额外安装。
安装 MogDB 容器版。
使用样本数据库 Mogila:
docker exec -it mogdb bash
omm@eb7aef3f860f:~$ gsql -d mogila -p5432
gsql ((MogDB x.x.x build 56189e20) compiled at 2022-01-07 18:47:53 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
mogila=# \dt
List of relations
Schema | Name | Type | Owner | Storage
--------+---------------+-------+-------+----------------------------------
public | actor | table | mogdb | {orientation=row,compression=no}
public | address | table | mogdb | {orientation=row,compression=no}
public | category | table | mogdb | {orientation=row,compression=no}
public | city | table | mogdb | {orientation=row,compression=no}
public | country | table | mogdb | {orientation=row,compression=no}
public | customer | table | mogdb | {orientation=row,compression=no}
public | film | table | mogdb | {orientation=row,compression=no}
public | film_actor | table | mogdb | {orientation=row,compression=no}
public | film_category | table | mogdb | {orientation=row,compression=no}
public | inventory | table | mogdb | {orientation=row,compression=no}
public | language | table | mogdb | {orientation=row,compression=no}
public | payment | table | mogdb | {orientation=row,compression=no}
public | rental | table | mogdb | {orientation=row,compression=no}
public | staff | table | mogdb | {orientation=row,compression=no}
public | store | table | mogdb | {orientation=row,compression=no}
(15 rows)
mogila=#
在 MogDB 企业版中使用 Mogila
安装 MogDB 企业版。
创建样本数据库 mogila 及 mogdb 用户,然后登出:
切换到omm用户
[root@test ~]# su - omm
登录postgres数据库,根据实际情况填写端口号
[omm@test ~]$ gsql -d postgres -p5432 -r
gsql ((MogDB x.x.x build 56189e20) compiled at 2022-01-07 18:47:53 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
MogDB=#create database mogila DBCOMPATIBILITY='PG';
CREATE DATABASE
MogDB=#create user mogdb password '*@';
CREATE ROLE
MogDB=#\q
[omm@test ~]$
下载 mogila,并上传至服务器中,进入 mogila 所在目录。
创建模式对象,然后手动插入数据:
4.1 创建所有模式对象(表等):
gsql -d mogila -p5432 -f mogila-schema.sql
4.2 插入所有数据:
gsql -d mogila -p5432 -f mogila-data.sql
复制
或者通过 1 个脚本创建模式对象并插入数据,如果您已经完成步骤 4.1 和 4.2,则无需执行步骤 5。
创建所有模式对象(表等)并插入所有数据:
gsql -d mogila -p5432 -f mogila-insert-data.sql
使用样本数据库 Mogila:
[omm@test ~]$ gsql -d mogila -p5432 -r
gsql ((MogDB x.x.x build 56189e20) compiled at 2022-01-07 18:47:53 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
mogila=# \dt
List of relations
Schema | Name | Type | Owner | Storage
--------+---------------+-------+-------+----------------------------------
public | actor | table | mogdb | {orientation=row,compression=no}
public | address | table | mogdb | {orientation=row,compression=no}
public | category | table | mogdb | {orientation=row,compression=no}
public | city | table | mogdb | {orientation=row,compression=no}
public | country | table | mogdb | {orientation=row,compression=no}
public | customer | table | mogdb | {orientation=row,compression=no}
public | film | table | mogdb | {orientation=row,compression=no}
public | film_actor | table | mogdb | {orientation=row,compression=no}
public | film_category | table | mogdb | {orientation=row,compression=no}
public | inventory | table | mogdb | {orientation=row,compression=no}
public | language | table | mogdb | {orientation=row,compression=no}
public | payment | table | mogdb | {orientation=row,compression=no}
public | rental | table | mogdb | {orientation=row,compression=no}
public | staff | table | mogdb | {orientation=row,compression=no}
public | store | table | mogdb | {orientation=row,compression=no}
(15 rows)
mogila=#
示例查询
本节通过一些查询来展示如何使用样本数据库 Mogila。所有查询结果仅展示前 10 项。
按长度排序列出所有电影
select film_id, title, length from film order by length desc;
| film_id | title | length |
|---|---|---|
| 426 | HOME PITY | 185 |
| 690 | POND SEATTLE | 185 |
| 609 | MUSCLE BRIGHT | 185 |
| 991 | WORST BANGER | 185 |
| 182 | CONTROL ANTHEM | 185 |
| 141 | CHICAGO NORTH | 185 |
| 349 | GANGS PRIDE | 185 |
| 212 | DARN FORRESTER | 185 |
| 817 | SOLDIERS EVOLUTION | 185 |
| 872 | SWEET BROTHERHOOD | 185 |
| 列出每个电影类别中有多少部电影 |
select category.name, count(category.name) category_count from category left join film_category on category.category_id = film_category.category_id left join film on film_category.film_id = film.film_id group by category.name order by category_count desc;
| name | category_count |
|---|---|
| Sports | 74 |
| Foreign | 73 |
| Family | 69 |
| Documentary | 68 |
| Animation | 66 |
| Action | 64 |
| New | 63 |
| Drama | 62 |
| Sci-Fi | 61 |
| Games | 61 |
| 显示按出演电影的数量排序的演员 |
select actor.first_name, actor.last_name, count(actor.first_name) featured_count from actor left join film_actor on actor.actor_id = film_actor.actor_id group by actor.first_name, actor.last_name order by featured_count desc;
| first_name | last_name | featured_count |
|---|---|---|
| SUSAN | DAVIS | 54 |
| GINA | DEGENERES | 42 |
| WALTER | TORN | 41 |
| MARY | KEITEL | 40 |
| MATTHEW | CARREY | 39 |
| SANDRA | KILMER | 37 |
| SCARLETT | DAMON | 36 |
| VIVIEN | BASINGER | 35 |
| VAL | BOLGER | 35 |
| GROUCHO | DUNST | 35 |
| 获取所有活跃客户的列表,按其姓名排序 |
select first_name, last_name from customer where active = 1 order by first_name asc;
| first_name | last_name |
|---|---|
| MARY | SMITH |
| PATRICIA | JOHNSON |
| LINDA | WILLIAMS |
| BARBARA | JONES |
| ELIZABETH | BROWN |
| JENNIFER | DAVIS |
| MARIA | MILLER |
| SUSAN | WILSON |
| MARGARET | MOORE |
| DOROTHY | TAYLOR |
| 查看租 DVD 数量最多的客户,以及租借次数 |
select customer.first_name, customer.last_name, count(customer.first_name) rentals_count from customer left join rental on customer.customer_id = rental.customer_id group by customer.first_name, customer.last_name order by rentals_count desc;
| first_name | last_name | rentals_count |
|---|---|---|
| ELEANOR | HUNT | 46 |
| KARL | SEAL | 45 |
| CLARA | SHAW | 42 |
| MARCIA | DEAN | 42 |
| TAMMY | SANDERS | 41 |
| WESLEY | BULL | 40 |
| SUE | PETERS | 40 |
| MARION | SNYDER | 39 |
| RHONDA | KENNEDY | 39 |
| TIM | CARY | 39 |
| 查看每个出租店的总收入 |
select store.store_id, sum(payment.amount) as "total revenue" from store left join inventory on inventory.store_id = store.store_id left join rental on rental.inventory_id = inventory.inventory_id left join payment on payment.rental_id = rental.rental_id where payment.amount is not null group by store.store_id order by sum(payment.amount) desc;
| store_id | total revenue |
|---|---|
| 2 | 33726.77 |
| 1 | 33689.74 |
| 按总收入列出前 5 个电影类型 |
select category.name, film.title, sum(payment.amount) as "gross revenue" from film left join film_category on film_category.film_id = film.film_id left join category on film_category.category_id = category.category_id left join inventory on inventory.film_id = film.film_id left join rental on rental.inventory_id = inventory.inventory_id left join payment on payment.rental_id = rental.rental_id where payment.amount is not null group by category.name, film.title order by sum(payment.amount) desc limit 5;
| name | title | gross revenue |
|---|---|---|
| Music | TELEGRAPH VOYAGE | 231.73 |
| Documentary | WIFE TURN | 223.69 |
| Comedy | ZORRO ARK | 214.69 |
| Sci-Fi | GOODFELLAS SALUTE | 209.69 |
| Sports | SATURDAY LAMBS | 204.72 |
| film.description 的数据类型为 text ,支持全文搜索查询,搜索所有包含documentary和robot的描述 |
select film.title, film.description from film where to_tsvector(film.description) @@ to_tsquery('documentary & robot');
| title | description |
|---|---|
| CASPER DRAGONFLY | A Intrepid Documentary of a Boat And a Crocodile who must Chase a Robot in The Sahara Desert |
| CHAINSAW UPTOWN | A Beautiful Documentary of a Boy And a Robot who must Discover a Squirrel in Australia |
| CONTROL ANTHEM | A Fateful Documentary of a Robot And a Student who must Battle a Cat in A Monastery |
| CROSSING DIVORCE | A Beautiful Documentary of a Dog And a Robot who must Redeem a Womanizer in Berlin |
| KANE EXORCIST | A Epic Documentary of a Composer And a Robot who must Overcome a Car in Berlin |
| RUNNER MADIGAN | A Thoughtful Documentary of a Crocodile And a Robot who must Outrace a Womanizer in The Outback |
| SOUTH WAIT | A Amazing Documentary of a Car And a Robot who must Escape a Lumberjack in An Abandoned Amusement Park |
| SWEDEN SHINING | A Taut Documentary of a Car And a Robot who must Conquer a Boy in The Canadian Rockies |
| VIRGIN DAISY | A Awe-Inspiring Documentary of a Robot And a Mad Scientist who must Reach a Database Administrator in A Shark Tank |
复制
清理
如需清理环境并删除样本数据库,请运行以下命令:
\c postgres;
DROP DATABASE mogila;
MogDB 使用样本数据集Mogila的更多相关文章
- Android恶意样本数据集汇总
硕士论文的研究方向为Android恶意应用分类,因此花了一点时间去搜集Android恶意样本.其中一部分来自过去论文的公开数据集,一部分来自社区或平台的样本.现做一个汇总,标明了样本或数据集的采集时间 ...
- 使用CIFAR-10样本数据集测试卷积神经网络(ConvolutionalNeuralNetwork,CNN)
第一次将例程跑起来了,有些兴趣. 参考的是如下URL: http://www.yidianzixun.com/article/0KNz7OX1 本来是比较Keras和Tensorflow的,我现在的水 ...
- 机器学习数据集,主数据集不能通过,人脸数据集介绍,从r包中获取数据集,中国河流数据集
机器学习数据集,主数据集不能通过,人脸数据集介绍,从r包中获取数据集,中国河流数据集 选自Microsoft www.tz365.Cn 作者:Lee Scott 机器之心编译 参与:李亚洲.吴攀. ...
- Recorder︱深度学习小数据集表现、优化(Active Learning)、标注集网络获取
一.深度学习在小数据集的表现 深度学习在小数据集情况下获得好效果,可以从两个角度去解决: 1.降低偏差,图像平移等操作 2.降低方差,dropout.随机梯度下降 先来看看深度学习在小数据集上表现的具 ...
- 怎么用Q-Q图验证数据集的分布
样本数据集在构建机器学习模型的过程中具有重要的作用,样本数据集包括训练集.验证集.测试集,其中训练集和验证集的作用是对学习模型进行参数择优,测试集是测试该模型的泛化能力. 正负样本数据集符合独立同分布 ...
- 机器学习经典分类算法 —— k-近邻算法(附python实现代码及数据集)
目录 工作原理 python实现 算法实战 约会对象好感度预测 故事背景 准备数据:从文本文件中解析数据 分析数据:使用Matplotlib创建散点图 准备数据:归一化数值 测试算法:作为完整程序验证 ...
- Python数模笔记-Sklearn(2)样本聚类分析
1.分类的分类 分类的分类?没错,分类也有不同的种类,而且在数学建模.机器学习领域常常被混淆. 首先我们谈谈有监督学习(Supervised learning)和无监督学习(Unsupervised ...
- [Python]-sklearn模块-机器学习Python入门《Python机器学习手册》-02-加载数据:加载数据集
<Python机器学习手册--从数据预处理到深度学习> 这本书类似于工具书或者字典,对于python具体代码的调用和使用场景写的很清楚,感觉虽然是工具书,但是对照着做一遍应该可以对机器学习 ...
- 机器学习——k-近邻算法
k-近邻算法(kNN)采用测量不同特征值之间的距离方法进行分类. 优点:精度高.对异常值不敏感.无数据输入假定 缺点:计算复杂度高.空间复杂度高 使用数据范围:数值型和标称型 工作原理:存在一个样本数 ...
- 机器学习实战笔记(Python实现)-01-K近邻算法(KNN)
--------------------------------------------------------------------------------------- 本系列文章为<机器 ...
随机推荐
- 【Azure 云服务】云服务(经典)迁移到云服务(外延支持)的八个问题
问题一:云服务( 经典)迁移到外延支持云服务是否需要停机? 通过平台的迁移工具(即验证.准备.提交)进行迁移没有停机时间.但是如果需要准备满足迁移条件,如删除对等互联,使用其他vnet资源则需要额外的 ...
- 【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
问题描述 使用微软云的Redis服务,导出它的RDB文件后,想把数据恢复到本地自建的Redis服务中,发现出现如下错误: 15000:S 21 Jun 08:14:11.199 * Retrying ...
- C++socket中select函数
文章参考 https://www.cnblogs.com/shmilxu/p/4835873.html
- Gavvmal
Gavvmal springboot 官方文档说明了两种方式,一种使用插件,直接生成docker镜像,但是这需要本地安装docker环境,但是无论用windows还是mac,本地安装docker都感觉 ...
- liunx 前台打包的两个报错 Invalid value used in weak set - MIS国产化服务器不支持打包
错误1 Invalid value used in weak set Webpack4使用 mini-css-extract-plugin 最新版 压缩css 报 "Invalid valu ...
- pod的拉取和重启策略
在Kubernetes中,Pod的拉取策略和重启策略可以通过YAML配置文件来定义. Pod的拉取策略 Pod的拉取策略指的是Kubernetes在创建或重启Pod时,如何获取Pod所需的容器镜像.这 ...
- 走进volatile的世界,探索它与可见性,有序性,原子性之间的爱恨情仇!
写在开头 在之前的几篇博文中,我们都提到了 volatile 关键字,这个单词中文释义为:不稳定的,易挥发的,在Java中代表变量修饰符,用来修饰会被不同线程访问和修改的变量,对于方法,代码块,方法参 ...
- Rust Rocket简单入门
目录 简介 hello world 常用功能 动态路径 多个片段(segments) 静态文件服务器 简单WebAPI示例 添加依赖 实现接口 接口测试 参考链接 简介 Rust中最知名的两个web框 ...
- Python实现简易版Netcat
Netcat Netcat是一种网络工具,也称为"nc",可用于在计算机网络之间进行TCP/IP或UDP连接.它可以用于连接到其他计算机上的端口,发送和接收数据,扫描端口以及创建服 ...
- Python 批量合并csv文件
一.批量合并csv文件<方法1> import pandas as pd import glob import os # 获取所有CSV文件的路径 file_paths = glob.gl ...