当前位置:网站首页>mysql的基础命令
mysql的基础命令
2022-07-06 06:26:00 【luckyyuanyuan】
sql区别大小写问题
创建数据表:
CREATE TABLE IF NOT EXISTS `runoob_tbl`(
`runoob_id` INT UNSIGNED AUTO_INCREMENT,
`runoob_title` VARCHAR(100) NOT NULL,
`runoob_author` VARCHAR(40) NOT NULL,
`submission_date` DATE,
PRIMARY KEY ( `runoob_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
1. 设置字段的属性为 NOT NULL, 在操作数据库时如果输入该字段的数据为NULL ,就会报错。
2. AUTO_INCREMENT定义列为自增的属性,一般用于主键,数值会自动加1。
3. PRIMARY KEY关键字用于定义列为主键。 您可以使用多列来定义主键,列间以逗号分隔。
4. ENGINE 设置存储引擎,CHARSET 设置编码。
根据表中某一列的“PH”字段查找数据,并限制只显示查找的前1000行
select * from dm_oss.d_f_oss_device_service_info where device_id like '%PH%' limit 1000
查询数据某一列中有哪些值(去重)
select distinct device_id from dm_oss.d_f_oss_device_service_info where device_id
指定被插入列名和值进行插入:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
在 “device_id ” 字段中查询属性值中含有 “PH” 的数据,并限制只展现1000行
select * from device_service_info where device_id like '%PH%' limit 1000

select * from device_basic_info where device_id like '%PH%' limit 1000

案例一: 多表联合查询与统计
表1:device_service_info
表2:device_basic_info
步骤1:查询1.4.9类的版本
// 在 “software_version ” 字段中查询属性值中含有 “1.4.9” 的数据
select device_id, description, software_version from device_basic_info having software_version like '%1.4.9%'

步骤2:根据service_start_time 字段选择某一段时间的数据
select device_id, service_id from device_service_info having service_start_time between "${day_start}" and "${day_end}"

步骤3:计算每个设备在指定的某段时间内的服务次数
select device_id, count(service_id) as service_sum from (select device_id, service_id from device_service_info having service_start_time between "${day_start}" and "${day_end}") group by device_id

步骤4:拼接两张表的信息,采取内连接,取其交集;
select t1.device_id, t1.service_sum, t2.description, software_version from ((select device_id, count(service_id) as service_sum from (select device_id, service_id from dm_oss .d_f_oss_device_service_info having service_start_time between "${day_start}" and "${day_end}") group by device_id) t1) inner join ((select device_id, description, software_version from dm_oss.d_f_oss_device_basic_info having software_version like '%1.4.9%') t2 )on t1.device_id = t2.device_id

边栏推荐
- Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
- Luogu p2089 roast chicken
- Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
- 模拟卷Leetcode【普通】1219. 黄金矿工
- Luogu p2141 abacus mental arithmetic test
- 模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
- Simulation volume leetcode [general] 1109 Flight reservation statistics
- 模拟卷Leetcode【普通】1314. 矩阵区域和
- My daily learning records / learning methods
- Simulation volume leetcode [general] 1218 Longest definite difference subsequence
猜你喜欢

Data type of MySQL

利用快捷方式-LNK-上线CS

Use shortcut LNK online CS

Career advancement Guide: recommended books for people in big factories

如何将flv文件转为mp4文件?一个简单的解决办法

Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis

Changes in the number of words in English papers translated into Chinese

Play video with Tencent video plug-in in uni app

Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board

如何做好互联网金融的英语翻译
随机推荐
国产游戏国际化离不开专业的翻译公司
MFC 动态创建的对话框及改变控件的大小和位置
Biomedical localization translation services
基於JEECG-BOOT的list頁面的地址欄參數傳遞
On weak network test of special test
电子书-CHM-上线CS
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
MFC关于长字符串unsigned char与CString转换及显示问题
Basic knowledge of MySQL
Simulation volume leetcode [general] 1314 Matrix area and
The internationalization of domestic games is inseparable from professional translation companies
Grouping convolution and DW convolution, residuals and inverted residuals, bottleneck and linearbottleneck
[mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
国际经贸合同翻译 中译英怎样效果好
金融德语翻译,北京专业的翻译公司
Convert the array selected by El tree into an array object
How much is it to translate Chinese into English for one minute?
Simulation volume leetcode [general] 1143 Longest common subsequence
模拟卷Leetcode【普通】1219. 黄金矿工
Past and present lives of QR code and sorting out six test points