找到 4219 篇文章 关于 MySQLi
507 次查看
在存储过程中创建表并使用 INSERT −mysql> DELIMITER // mysql> CREATE PROCEDURE create_TableDemo(id int,name varchar(100),age int) BEGIN CREATE TABLE DemoTable ( ClientId int NOT NULL, ClientName varchar(30), ClientAge int, PRIMARY KEY(ClientId) ); INSERT INTO DemoTable VALUES(id,name,age); SELECT *FROM DemoTable; END // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;使用 CALL 命令调用存储过程 −mysql> CALL create_TableDemo(100,'Robert',28);这将产生以下输出 −+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 100 | Robert | 28 | +----------+------------+-----------+ 1 row in set (0.76 sec) Query OK, 0 rows affected (0.78 sec)
225 次查看
要获取最后日期(即最新的日期),请使用聚合函数 MAX() 和子查询。让我们首先创建一个表 −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ExpiryDate date ); Query OK, 0 rows affected (1.40 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable(ExpiryDate) values('2018-12-31'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(ExpiryDate) values('2019-09-01'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(ExpiryDate) values('2019-09-01'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(ExpiryDate) values('2016-08-30'); Query OK, 1 row affected (0.13 ... 阅读更多
150 次查看
是的,将 AUTO_INCREMENT 与 PRIMARY KEY 一起使用。让我们首先创建一个表 −mysql> create table DemoTable ( EmployeeId int NOT NULL AUTO_INCREMENT, EmployeeName varchar(40), EmployeeAge int, PRIMARY KEY(EmployeeId), UNIQUE KEY(EmployeeName, EmployeeAge) ); Query OK, 0 rows affected (0.96 sec)让我们检查表的表描述 −mysql> desc DemoTable;这将产生以下输出 −+--------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+----------------+ | EmployeeId | int(11) | NO | PRI | NULL ... 阅读更多
190 次查看
为此,您可以使用子查询。让我们首先创建一个表 −mysql> create table DemoTable ( Score int ); Query OK, 0 rows affected (0.62 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(55); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.13 sec)显示所有记录 ... 阅读更多
328 次查看
为此,请使用 GROUP BY HAVING 子句。让我们首先创建一个表 −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.54 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(99); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(99); Query OK, 1 row affected (0.09 sec) mysql> insert ... 阅读更多
413 次查看
要计算逗号分隔的值,请使用聚合函数 COUNT(*) 和 FIND_IN_SET()。让我们首先创建一个表 −mysql> create table DemoTable ( Value varchar(100) ); Query OK, 0 rows affected (0.49 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable values('10, 20, 60, 80'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('60, 70, 90'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('50, 55, 65, 60'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('90, 98, 97'); Query OK, 1 row affected (0.12 sec)显示所有记录 ... 阅读更多
136 次查看
为此,请使用 MySQL 的 INSERT() 函数。INSERT(str, pos, len, newstr) 返回字符串 str,其中从位置 pos 开始的长度为 len 的子字符串被字符串 newstr 替换。如果 pos 不在字符串长度内,则返回原始字符串。如果 len 不在字符串其余部分的长度内,则替换从位置 pos 开始的字符串其余部分。如果任何参数为 NULL,则返回 NULL。让我们首先创建一个表 −mysql> create table DemoTable ( Password varchar(50) ); Query OK, 0 rows affected (0.51 sec)在 ... 中插入一些记录 阅读更多
92 次查看
让我们首先创建一个表 −mysql> create table DemoTable ( Name varchar(40), Score int ); Query OK, 0 rows affected (0.48 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable values('Adam', 89); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Adam', 89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris', 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris', 89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob', 98); Query OK, 1 row affected (0.10 sec) mysql> insert ... 阅读更多
906 次查看
为此,您可以使用子查询。让我们首先创建一个表 −mysql> create table DemoTable ( StudentName varchar(40), StudentMarks int ); Query OK, 0 rows affected (0.50 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable values('Adam', 56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris', 78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Adam', 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert', 98); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris', 65); Query OK, 1 ... 阅读更多
1K+ 次查看
要生成行索引,请使用 ROW_NUMBER()。让我们首先创建一个表 −mysql> create table DemoTable ( Name varchar(40) ); Query OK, 0 rows affected (0.49 sec)使用 insert 命令在表中插入一些记录 −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... 阅读更多