随笔分类 - SQL
摘要:安装PostgreSQL sudo apt install postgresql postgresql-contrib # 如果您需要特定版本,请使用“postgresql-12”或类似版本,替换“postgresql”: postgresql-contrib软件包包含了一些有用的扩展和附加功能。
阅读全文
摘要:1. 升序 select time,A from table1 order by time asc limit 10; + + +| time | A |+ + +| 2022-12-14 20:40:32 | 294.368 || 2022-12-14 20:41:02 | 293.819 ||
阅读全文
摘要:select ...into outfile语法是mysql提供的一种数据导出的方案,支持自定义导出数据格式。 例如:将test表的所有数据全部导出到test.txt文件。 select * from test into outfile '/tmp/test.txt'; 更常用的方法是将表数据导出成
阅读全文
摘要:一、Event创建语法 CREATE Event [IF NOT EXISTS] event_name -- 创建使用create event ON SCHEDULE schedule -- on schedule 什么时候来执行,执行频率 [ON COMPLETION [NOT] PRESERVE
阅读全文
摘要:同一表内UPDATE数据 mysql> select * from test1; + + + + + + + | id | a | b | c | d | e | + + + + + + + | 1 | 34 | 6 | 10 | 0 | 2 | | 2 | 22 | 5 | 22 | 0 | 5
阅读全文
摘要:DELETE A FROM Table_name A JOIN (SELECT id FROM table_name ORDER BY id DESC LIMIT 10,1) B WHERE A.id<=B.id
阅读全文
摘要:1、确定mysql数据库文件存放目录 1 show variables like '%dir%'; 2、停止mysql数据库服务: 1 sudo /etc/init.d/mariadb stop 3、 迁移数据库至新目录 目标文件夹:/mnt/data/ 1 2 3 sudo mv /var/lib
阅读全文
摘要:第二种方法: select ('语文')subject , (select chinese from score) value from dual union select ('数学')subject , (select math from score) value from dual union
阅读全文
摘要:表格1:表名:score + + + + + + | name | chinese | english | math | total | + + + + + + | Tom | 90 | 80 | 100 | 270 | + + + + + + 表格2: + + + | subject | valu
阅读全文
摘要:MySQL 使用 ALTER TABLE 语句修改表。修改表指的是修改数据库中已经存在的数据表的结构。常用的修改表的操作有修改表名、修改字段数据类型或字段名、增加和删除字段、修改字段的排列位置、更改表的存储引擎、删除表的外键约束等。 常用的语法格式如下:ALTER TABLE <表名> [修改选项]
阅读全文
摘要:查看功能是否打开 mysql> show global variables like 'local_infile'; + + + | Variable_name | Value | + + + | local_infile | OFF | + + + 1 row in set (0.00 sec)
阅读全文
摘要:1、取数据库最后30个数据 select x,y from sin order by id desc limit 0,30; 2、将数据再反序,横坐标反转 select * from (select x,y from sin order by id desc limit 0,30) as sinxy
阅读全文
摘要:表1 course mysql> select * from course; + + + | id | course_name | + + + | 1 | Java | | 2 | MySQL | | 3 | Python | | 4 | Go | | 5 | C++ | + + + 5 rows
阅读全文
摘要:表 course mysql> select * from course; + + + | id | course_name | + + + | 1 | Java | | 2 | MySQL | | 3 | Python | | 4 | Go | | 5 | C++ | + + + 5 rows i
阅读全文
摘要:表一 mysql> select * from departments; + + + | department_id | dept_name | + + + | 1 | Sales | | 2 | Markting | | 3 | Finance | | 4 | Accounting | | 5 |
阅读全文