找到 4379 篇文章 关于 MySQL
1K+ 浏览量
为此,使用 GROUP BY 和 HAVING。让我们先创建一个表 -mysql> create table DemoTable ( StudentName varchar(100), DueDate date ); Query OK, 0 rows affected (0.72 sec)示例使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('John', '2019-01-11'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('Chris', '2019-02-11'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Chris', '2019-03-11'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('John', '2019-04-11'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Bob', '2019-05-11'); ... 阅读更多
742 浏览量
是的,替代方法是 CONCAT_WS()。让我们先创建一个表 -mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) ); Query OK, 0 rows affected (0.74 sec)示例使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;输出+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | ... 阅读更多
340 浏览量
为此,使用 REPLACE() 函数并将空空间替换为字符。让我们先创建一个表 -mysql> create table DemoTable (Subject text); Query OK, 0 rows affected (0.86 sec)示例使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Java in depth'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Data Structure and Algorithm'); Query OK, 1 row affected (0.16 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;输出+------------------------------+ | Subject | +------------------------------+ | Introduction ... 阅读更多
358 浏览量
使用索引可以有效地选择前 n 行。让我们先创建一个表 -mysql> create table DemoTable (StudentName varchar(100), StudentScore int ); Query OK, 0 rows affected (0.66 sec)示例使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('John', 34); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Carol', 55); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob', 58); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Sam', 38); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Mike', 48); Query OK, 1 row ... 阅读更多
79 浏览量
为此,您可以使用 CHAR_LENGTH()。使用 RAND() 获取随机记录。让我们先创建一个表 -mysql> create table DemoTable (Subject text); Query OK, 0 rows affected (0.61 sec)示例使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('C'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('MySQL'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('MongoDB'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('RubyOnRails'); Query OK, 1 row affected (0.25 sec) mysql> insert ... 阅读更多
409 浏览量
为此,您可以使用 LAST_INSERT_ID()。让我们先创建一个表 -mysql> create table DemoTable ( UserId int(6) unsigned zerofill NOT NULL AUTO_INCREMENT, UserAutoIncrement char(100) default null, PRIMARY KEY(UserId) ); Query OK, 0 rows affected (0.72 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(); Query OK, 1 row affected (0.13 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;输出+--------+-------------------+ | UserId | UserAutoIncrement | +--------+-------------------+ | 000001 | NULL | +--------+-------------------+ ... 阅读更多
261 浏览量
要将秒舍入到最接近的半分钟,请使用 CEILING()。让我们先创建一个表 -mysql> create table DemoTable (secondValue int); Query OK, 0 rows affected (0.64 sec)示例使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(27); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(118); Query OK, 1 row affected (0.20 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;输出+-------------+ | secondValue | +-------------+ | 27 | | 56 ... 阅读更多
1K+ 浏览量
为此,您可以使用 COUNT() 函数。让我们先创建一个表 -mysql> create table DemoTable -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(100) -> ); Query OK, 0 rows affected (0.62 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable(EmployeeName) values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(EmployeeName) values('Carol'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(EmployeeName) values('Carol'); Query OK, 1 row affected ... 阅读更多
821 浏览量
为此,使用 MySQL 中的 COALESCE() 函数。让我们先创建一个表 -mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int -> ); Query OK, 0 rows affected (0.51 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(100, 200); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(NULL, 90); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(NULL, NULL); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(600, NULL); Query OK, 1 row affected (0.12 sec)显示所有记录 ... 阅读更多
324 浏览量
让我们先创建一个表 -mysql> create table DemoTable -> ( -> Amount int -> ); Query OK, 0 rows affected (0.99 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.13 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;输出这将产生以下输出 -+--------+ | Amount | +--------+ | 100 | | 200 ... 阅读更多