找到 4219 篇文章 关于 MySQLi
385 次查看
为此,您可以使用 ORDER BY CAST()。让我们看一个例子 -mysql> create table DemoTable2006 ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserCode varchar(20) ); Query OK, 0 rows affected (1.14 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2006(UserCode) values('John_12'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable2006(UserCode) values('John_34'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2006(UserCode) values('John_56'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2006(UserCode) values('Chris_101'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable2006(UserCode) values('Chris_103'); Query ... 阅读更多
332 次查看
要从具有相应重复 ID 的列中获取最小值,请使用 GROUP BY 和 MIN() -select min(yourColumnName) from yourTableName group by yourColumnName;为了理解上述语法,让我们创建一个表 -mysql> create table DemoTable2005 ( Id int, Price float ); Query OK, 0 rows affected (0.71 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2005 values(1, 56.88); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2005 values(1, 120.56); Query OK, 1 row affected (0.23 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable2005;这将产生 ... 阅读更多
199 次查看
让我们首先创建一个表 -mysql> create table DemoTable2004 ( UserId varchar(20), UserName varchar(20) ); Query OK, 0 rows affected (0.57 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2004 values('John_123', 'John'); Query OK, 1 row affected (0.93 sec) mysql> insert into DemoTable2004 values('23456_Carol', 'Carol'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable2004 values('111_Bob', 'Bob'); Query OK, 1 row affected (0.14 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable2004;这将产生以下输出 -+-------------+----------+ | UserId | UserName | +-------------+----------+ | ... 阅读更多
773 次查看
要显示来自相应重复 ID 的最高金额,请使用 MAX() 以及 GROUP BY 子句 -mysql> create table DemoTable2003 ( CustomerId int, Amount int ); Query OK, 0 rows affected (0.65 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2003 values(101, 560); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2003 values(102, 1080); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2003 values(101, 570); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable2003 values(102, 870); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable2003 values(101, 460); ... 阅读更多
103 次查看
要在 MySQL 中对日期进行分组,请使用 GROUP BY 子句 -mysql> create table DemoTable2002 ( CustomerName varchar(20), CustomerShippingDate datetime ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2002 values('Chris', '2019-01-10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2002 values('David', '2018-12-31'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2002 values('David', '2019-12-16'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2002 values('Chris', '2018-12-01'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录 -mysql> select * ... 阅读更多
78 次查看
要使用用户定义变量获取最大考试日期,代码如下 -select date(max(yourColumnName )) into @yourVariableName from yourTableName;为了理解上述语法,让我们首先创建一个表 -mysql> create table DemoTable2001 ( ExamDate date ); Query OK, 0 rows affected (0.60 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2001 values('2019-01-10'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2001 values('2018-12-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2001 values('2018-11-18'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable2001 values('2019-07-25'); Query OK, 1 ... 阅读更多
316 次查看
要显示正确的单引号,您需要使用 COLLATE='utf8_unicode_ci' 修改表。让我们首先创建一个表 -mysql> create table DemoTable2000 ( Name varchar(20) ); Query OK, 0 rows affected (0.81 sec)以下是使用 collate 的查询 -mysql> ALTER TABLE DemoTable2000 COLLATE='utf8_unicode_ci'; Query OK, 0 rows affected (0.90 sec) Records: 0 Duplicates: 0 Warnings: 0使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable2000 values('Chris’s Brown'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable2000 values('David’s Miller'); Query OK, 1 row affected (0.67 sec) mysql> insert into DemoTable2000 values('Robert’s Downey'); Query ... 阅读更多
173 次查看
要仅返回月份名称,您可以使用 DATE_FORMAT() -mysql> create table DemoTable1999 ( ArrivalDate timestamp ); Query OK, 0 rows affected (0.66 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1999 values('2019-01-01 12:34:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1999 values('2019-12-31 10:04:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1999 values('2018-10-11 04:04:30'); Query OK, 1 row affected (0.14 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1999;这将产生以下输出 -+---------------------+ | ArrivalDate | +---------------------+ ... 阅读更多
884 次查看
要从重复行中仅返回一行,请使用 DISTINCT 关键字 -mysql> create table DemoTable1998 ( Name varchar(20) ); Query OK, 0 rows affected (0.61 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1998 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1998 values('Robert'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1998 values('David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1998 values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1998 ... 阅读更多
720 次查看
要将日期转换为UNIX时间戳,请在MySQL中使用UNIX_TIMESTAMP()函数−mysql> create table DemoTable1997 ( DueDate date ); Query OK, 0 rows affected (0.58 sec)使用insert命令在表中插入一些记录−mysql> insert into DemoTable1997 values('2018-10-11'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2019-12-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1997 values('2017-01-31'); Query OK, 1 row affected (0.11 sec)使用select语句显示表中的所有记录−mysql> select * from DemoTable1997;这将产生以下输出−+------------+ | DueDate | +------------+ | 2018-10-11 | | 2019-12-21 | ... 阅读更多