找到 4219 篇文章 关于 MySQLi
665 次浏览
要按 MySQL 中列的长度排序,请使用 ORDER BY LENGTH。让我们先创建一个表 -mysql> create table DemoTable715 (UserMessage varchar(100)); Query OK, 0 rows affected (0.56 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable715 values('Aw'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable715 values('Awe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable715 values('A'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable715 values('Awes'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable715 values('Awesom'); Query OK, 1 row affected (0.16 sec) mysql> insert ... 阅读更多
941 次浏览
让我们先创建一个表 -mysql> create table DemoTable1 (FirstName varchar(100)); Query OK, 0 rows affected (0.54 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1 values('Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1 values('James'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1 values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1 values('David'); Query OK, 1 row affected (0.18 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable1;这将产生以下输出 -+-----------+ | FirstName | +-----------+ | Bob ... 阅读更多
2K+ 次浏览
让我们先创建一个表 -mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (1.40 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(100, 'John'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(102, 'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(103, 'Chris'); Query OK, 1 row affected (1.05 sec) mysql> insert into DemoTable values(104, 'David'); Query OK, 1 ... 阅读更多
1K+ 次浏览
要比较日期字符串,请使用 MySQL 中的 STR_TO_DATE()。让我们先创建一个表 -mysql> create table DemoTable712 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ArrivalDate varchar(100) ); Query OK, 0 rows affected (0.65 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable712(ArrivalDate) values('10.01.2019'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable712(ArrivalDate) values('11.12.2018'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable712(ArrivalDate) values('01.11.2017'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable712(ArrivalDate) values('20.06.2016'); Query OK, 1 row affected (0.23 sec)使用 select ... 阅读更多
93 次浏览
IN 在 MySQL 中使用索引,而 OR 不使用索引。让我们先创建一个表 -mysql> create table DemoTable711 ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.92 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable711 values(100, 'Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable711 values(101, 'Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable711 values(102, 'Carol'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable711 values(103, 'Mike'); Query OK, 1 row affected (0.17 sec) mysql> insert ... 阅读更多
126 次浏览
为此,请使用 INTERVAL 8 MONTH 并从当前日期获取 8 个月后的记录 -select *from yourTableName where yourColumnName>= (CURRENT_DATE() - INTERVAL 8 MONTH);注意 - 假设当前日期为:2018-02-06让我们先创建一个表 -mysql> create table DemoTable (StudentName varchar(100), AdmissionDate date); Query OK, 0 rows affected (0.75 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('John', '2019-01-21'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('Chris', '2019-10-04'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('Robert', '2018-02-01'); Query OK, 1 row affected (0.16 sec) ... 阅读更多
1K+ 次浏览
数据库错误 #1064 可能是由于语法错误导致的。例如,假设我们正在创建以下表 -mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100), UserAge int, UserAddress varchar(200), UserCountryName varchar(100) , isMarried boolean, );这将产生以下输出,即错误 -ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' ... 阅读更多
178 次浏览
您不能在开头使用 @ 为 MySQL 存储过程参数赋值。您可以在用户定义的变量中使用 @ 符号。以下是语法 -SET @yourVariableName=yourValue;让我们实现上述语法以正确放置 @ 符号 -mysql> DELIMITER // mysql> CREATE PROCEDURE declare_Variable(IN StudentName varchar(100)) BEGIN SET @Name=StudentName; SELECT @Name; END // Query OK, 0 rows affected (0.12 sec) mysql> DELIMITER ;现在您可以使用 CALL 命令调用存储过程 -mysql> call declare_Variable('John Smith');这将产生以下输出 -+------------+ | @Name | +------------+ | John Smith | +------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected, 1 warning (0.03 sec)
147 次浏览
是的,使用 ON DUPLICATE KEY UPDATE。让我们先创建一个表 -mysql> create table DemoTable(Id int NOT NULL PRIMARY KEY, Number int); Query OK, 0 rows affected (0.83 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(1, 190) ON DUPLICATE KEY UPDATE Number=Number+10; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(2, 130) ON DUPLICATE KEY UPDATE Number=Number+10; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(1, 190) ON DUPLICATE KEY UPDATE Number=Number+10; Query OK, 2 rows affected (0.14 sec) mysql> insert into DemoTable values(2, 130) ON DUPLICATE ... 阅读更多
367 次浏览
为此,请使用 IFNULL()。让我们先创建一个表 -mysql> create table DemoTable (Value int); Query OK, 0 rows affected (1.02 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.13 sec)使用 select 语句显示表中的所有记录 -mysql> ... 阅读更多