找到关于 MySQLi 的4219 篇文章
1K+ 次浏览
使用 CREATE TABLE IF NOT EXISTS,如下面的语法所示:create table if not exists yourTableName ( yourColumnName1 dataType, yourColumnName2 dataType, yourColumnName3 dataType, . . N ) as select yourValue1 as yourColumnName1 , yourValue2 as yourColumnName2 , yourValue3 as yourColumnName3, .............................N;让我们首先创建一个表,如果表不存在则插入值:mysql> create table if not exists DemoTable ( id int, FirstName varchar(20), LastName varchar(20) ) as select 100 as id, 'John' as FirstName , 'Smith' as LastName; Query OK, 1 row ... 阅读更多
515 次浏览
让我们首先创建一个表:mysql> create table DemoTable ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ProductAmount int, CustomerCountryName varchar(10) ); Query OK, 0 rows affected (0.86 sec)使用insert命令在表中插入一些记录:mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(190, 'US'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(200, 'UK'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(1500, 'AUS'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(2010, 'US'); Query OK, 1 row affected (0.13 sec) mysql> insert into ... 阅读更多
218 次浏览
要显示单引号文本,请使用双引号,例如,如果要编写 You’ve,则在插入时编写 You've,即使用双引号。让我们首先创建一个表:mysql> create table DemoTable ( Note text ); Query OK, 0 rows affected (0.57 sec)使用insert命令在表中插入一些记录:mysql> insert into DemoTable values('You''ve seen the Taj? When?'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('You''ve visited the US?'); Query OK, 1 row affected (0.16 sec)使用select语句显示表中的所有记录:mysql> select *from DemoTable;这将产生... 阅读更多
83 次浏览
要仅将空单元格更新为 NULL,请在 MySQL 中使用 NULLIF()。让我们首先创建一个表:mysql> create table DemoTable ( Name varchar(50) ); Query OK, 0 rows affected (1.73 sec)使用insert命令在表中插入一些记录:mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.15 ... 阅读更多
3K+ 次浏览
让我们看看第一个语法,它在 MAX() 中使用 DISTINCT:select max(DISTINCT yourColumnName) from yourTableName;第二个语法如下所示。它没有使用 DISTINCT:select max( yourColumnName) from yourTableName;注意 - 以上两个查询无论是否使用 DISTINCT 关键字,结果都相同。MySQL 内部将 MAX(yourColumnName) 转换为 DISTINCT 关键字。让我们现在来看一个例子并创建一个表:mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (1.50 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.09 sec) mysql> insert into ... 阅读更多
410 次浏览
为此,使用 COALESCE()。让我们实现一个存储过程来检查局部变量是否为 null:mysql> DELIMITER // mysql> CREATE PROCEDURE local_VariableDemo() BEGIN DECLARE value1 int; DECLARE value2 int; select value1, value2; select concat('After checking local variable is null the sum is = ', COALESCE(value1, 0)+COALESCE(value2, 0)); END // Query OK, 0 rows affected (0.19 sec) mysql> DELIMITER ;使用 CALL 命令调用存储过程:mysql> call local_VariableDemo();这将产生以下输出:+--------+--------+ | value1 | value2 | +--------+--------+ | NULL | NULL | +--------+--------+ 1 ... 阅读更多
110 次浏览
对于基于条件的更新,请使用 UPDATE 和 IF()。让我们首先创建一个表:mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.47 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.10 sec)显示所有记录... 阅读更多
1K+ 次浏览
让我们首先创建一个表:mysql> create table DemoTable ( `Values` varchar(50) ); Query OK, 0 rows affected (1.15 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('23, 45, 78, 56'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('384, 476, 7456'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('68, 8, 88, 89'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('78, 80, 84'); Query OK, 1 row affected (0.19 sec)使用 select 语句显示表中的所有记录:mysql> select *from DemoTable;这... 阅读更多
189 次浏览
让我们首先创建一个表:mysql> create table DemoTable ( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeName varchar(40), isMarried boolean ); Query OK, 0 rows affected (0.57 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable(EmployeeName, isMarried) values('Chris', true); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(EmployeeName, isMarried) values('Robert', false); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(EmployeeName, isMarried) values('Mike', false); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(EmployeeName, isMarried) values('Bob', true); Query OK, 1 row affected (0.07 sec) mysql> insert into ... 阅读更多