找到 4219 篇文章 关于 MySQLi
71 次浏览
为此,您可以使用 UNION ALL 以及 WHERE NOT EXISTS 并实现 NOT IN 来忽略表中已有的值。使用 SELECT 与 UNION ALL 来添加表中不存在的值。让我们首先创建一个表 - mysql> create table DemoTable1918 ( Value int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1918 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1918 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into ... 阅读更多
129 次浏览
要获取除第一行和最后一行之外的所有行,请使用子查询以及 MIN() 和 MAX()。让我们首先创建一个表 - mysql> create table DemoTable1917 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentCode int, StudentMarks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1917(StudentCode, StudentMarks) values(78, 95); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1917(StudentCode, StudentMarks) values(78, 96); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1917(StudentCode, StudentMarks) values(78, 97); Query OK, 1 row affected (0.00 ... 阅读更多
137 次浏览
为此,使用 MySQL CASE 语句设置条件 - mysql> create table DemoTable1916 ( StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1916 values('Chris', 59); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('David', 89); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('Sam', 94); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('Mike', 75); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('Carol', 69); Query OK, 1 row affected ... 阅读更多
221 次浏览
要设置 NOT NULL,请使用 IS NOT NULL 并查找值。语法如下 - select if('' is not NULL, 1, 0) as anyAliasName;以下是工作查询 - mysql> select if('' is not NULL, 1, 0);这将产生以下输出 - +------------------------+ | if('' is not NULL, 1, 0) | +------------------------+ | 1 | +------------------------+ 1 row in set (0.00 sec)为了理解上述语法,让我们创建一个表 - mysql> create table DemoTable1915 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)插入 ... 阅读更多
220 次浏览
为此,请使用 SET yourColumnName = NULL,如下面的语法所示 - update yourTableName set yourColumnName=NULL where yourColumnName=yourValue;让我们首先创建一个表 - mysql> create table DemoTable1914 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Code varchar(20) )AUTO_INCREMENT=1001; Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1914(Code) values('John101'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1914(Code) values('234David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1914(Code) values('100_Mike'); Query OK, 1 row affected (0.00 sec)使用 select 命令显示表中的所有记录 ... 阅读更多
162 次浏览
要追加 000,请使用 ZEROFILL 的概念。让我们首先创建一个表 - mysql> create table DemoTable1913 ( Code int(4) ZEROFILL AUTO_INCREMENT NOT NULL, PRIMARY KEY(Code) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1913 values(1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1913 values(2); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1913 values(3); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1913 values(4); Query OK, 1 row affected (0.00 sec)显示表中的所有记录 ... 阅读更多
169 次浏览
为此,请使用 ORDER BY 以及 LIMIT。让我们首先创建一个表,其中包含一个带有用户 ID、登录时间和名称的列 - mysql> create table DemoTable1911 ( UserId int, UserLoggedInTime time, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1911 values(100, '7:32:00', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1911 values(101, '5:00:00', 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1911 values(102, '6:10:20', 'Mike'); Query OK, 1 row affected (0.00 ... 阅读更多
508 次浏览
为此,您可以使用 CASE WHEN 语句。让我们首先创建一个表 - mysql> create table DemoTable1910 ( FirstName varchar(20), Marks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 - mysql> insert into DemoTable1910 values('Chris', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('David', 85); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('Chris', 55); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('Chris', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1910 values('David', ... 阅读更多
169 次浏览
要返回数据库列表,语法如下:select schema_name as anyAliasName from information_schema.schemata;以下是返回 MySQL 中数据库列表的查询:mysql> select schema_name as DatabaseName from information_schema.schemata;这将产生以下输出:+---------------------------+ | DatabaseName | +---------------------------+ | mysql | | information_schema | | performance_schema | | sys | | business | | sample | | hello | | test | | mybusiness | | databasesample | | schemasample | | universitydatabase | | education | | mydatabase | | database1 | | sampledatabase | | test3 | | javadatabase2 | | javasampledatabase | | rdb | | onetomanyrelationship | | webtracker | | web | | commandline | | hb_student_tracker | | bothinnodbandmyisam | | customertracker | | tracker | | demo | | customer_tracker_database | | login | | onlinebookstore | | customer-tracker | | web_tracker | | instant_app | | 1233 | +---------------------------+ 36 rows in set (0.00 sec)
428 次浏览
为此,您只需要使用一次 SET 命令。让我们首先创建一个表:mysql> create table DemoTable1909 ( Id int NOT NULL, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1909 values(101, 'John', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1909 values(102, 'John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1909 values(103, 'Adam', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1909 values(104, 'David', 'Miller'); Query ... 阅读更多