找到 4379 篇文章 关于 MySQL
1K+ 次浏览
您可以使用 MySQL 中的 LEFT() 函数。让我们先创建一个表 -mysql> create table DemoTable1428 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20) -> ); Query OK, 0 rows affected (1.05 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1428(EmployeeName) values('Chris Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1428(EmployeeName) values('Bob Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1428(EmployeeName) values('John Smith'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1428(EmployeeName) values('David Miller'); Query OK, 1 row affected (0.18 sec) ... 阅读更多
439 次浏览
为此,您可以使用子查询。让我们先创建一个表 -mysql> create table DemoTable1427 -> ( -> StudentId int, -> StudentMarks int -> ); Query OK, 0 rows affected (1.28 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1427 values(201, 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1427 values(201, 99); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1427 values(210, 98); Query OK, 1 row affected (0.16 sec)使用 select 命令显示表中的所有记录 -mysql> select * from DemoTable1427 ;这将产生以下输出 ... 阅读更多
73 次浏览
为此,您可以使用 ORDER BY RAND() 和 LIMIT。让我们先创建一个表 -mysql> create table DemoTable1426 -> ( -> FirstName varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1426 values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1426 values('Adam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1426 values('Robert'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1426 values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1426 values('Sam'); Query OK, 1 row ... 阅读更多
152 次浏览
是的,您可以将聚合函数 COUNT(*) 与 GROUP BY 子句一起使用。让我们先创建一个表 -mysql> create table DemoTable1425 -> ( -> JoiningYear int -> ); Query OK, 0 rows affected (0.76 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1425 values(2000); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1425 values(2010); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1425 values(2015); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1425 values(2000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1425 values(2010); Query OK, ... 阅读更多
248 次浏览
为此,请使用 CONCAT() 和 SUBSTRING_INDEX()。让我们先创建一个表 -mysql> create table DemoTable1424 -> ( -> Value varchar(60) -> ); Query OK, 0 rows affected (0.56 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1424 values('567.78483733'); Query OK, 1 row affected (0.78 sec) mysql> insert into DemoTable1424 values('1023.45252443'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1424 values('7893322.5635543434'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1424 values('90944.665665'); Query OK, 1 row affected (0.14 sec)使用 select 命令显示表中的所有记录 -mysql> select * from DemoTable1424;这 ... 阅读更多
2K+ 次浏览
使用 FIND_IN_SET() 而不是 MySQL IN()。让我们先创建一个表 -mysql> create table DemoTable1423 -> ( -> CountryName varchar(100) -> ); Query OK, 0 rows affected (0.51 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1423 values('AUS, UK'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1423 values('US'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1423 values('AUS, UK, US'); Query OK, 1 row affected (0.13 sec)使用 select 命令显示表中的所有记录 -mysql> select * from DemoTable1423;这将产生以下输出 −+-------------+ | CountryName | +-------------+ ... 阅读更多
634 次浏览
要选择两个日期范围内的所有数据,请使用 MySQL BETWEEN -select * from yourTableName where yourColumnName between yourDateValue1 and yourDateValue2;让我们先创建一个表 -mysql> create table DemoTable1422 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeJoiningDate date -> ); Query OK, 0 rows affected (0.69 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1422(EmployeeName, EmployeeJoiningDate) values('John', '2017-09-28'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable1422(EmployeeName, EmployeeJoiningDate) values('Chris', '2019-09-29'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1422(EmployeeName, EmployeeJoiningDate) ... 阅读更多
682 次浏览
要设置条件,请使用 MySQL CASE 语句。让我们先创建一个表 -mysql> create table DemoTable1481 -> ( -> PlayerScore int -> ); Query OK, 0 rows affected (0.42 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1481 values(454); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable1481 values(765); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1481 values(890); Query OK, 1 row affected (0.09 sec)使用 select 命令显示表中的所有记录 -mysql> select * from DemoTable1481;这将产生以下输出 −+-------------+ | PlayerScore | +-------------+ | ... 阅读更多
167 次浏览
是的,我们可以获取,但是对条件使用 MySQL OR。让我们先创建一个表 -mysql> create table DemoTable1421 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeSalary int -> ); Query OK, 0 rows affected (0.82 sec)使用 insert 命令插入一些记录 -mysql> insert into DemoTable1421(EmployeeName, EmployeeSalary) values('Chris', 10000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1421(EmployeeName, EmployeeSalary) values('Bob', 15000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1421(EmployeeName, EmployeeSalary) values('David', 8000); Query OK, 1 row affected (0.09 sec) mysql> insert ... 阅读更多