找到 4219 篇文章 关于 MySQLi
370 次查看
要在逗号分隔的列表中搜索,请使用 MySQL find_in_set()。此处不需要为此目的使用正则表达式。语法如下:select *from yourTableName where find_in_set(anyValue, yourColumnName);让我们创建一个表:mysql> create table demo17 −> ( −> id int not null auto_increment primary key, −> first_name varchar(50), −> value text −> ); Query OK, 0 rows affected (1.81 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo17(first_name, value) values('John', '50'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo17(first_name, value) values('David', ''); Query OK, 1 ... 阅读更多
211 次查看
使用 extract() 方法以及 cast() 进行提取。以下是语法:select extract(minute from cast(yourColumnName as time)) as anyAliasName from yourTableName;让我们创建一个表:mysql> create table demo15 −> ( −> value time −> ); Query OK, 0 rows affected (2.11 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo15 values('10:30:45'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo15 values('06:34:55'); Query OK, 1 row affected (0.17 sec)使用 select 语句显示表中的记录:mysql> select *from demo15;这将产生以下输出:+----------+ | value ... 阅读更多
362 次查看
要删除重复列,请使用带有 INNER JOIN 的 DELETE。以下是语法:delete tbl1 from yourTableName anyAliasName1 inner join yourTableName anyAliasName2 where yourCondition1 and yourCondition2让我们创建一个表:mysql> create table demo14 −> ( −> id int not null auto_increment primary key, −> name varchar(30) −> ); Query OK, 0 rows affected (1.89 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo14(name) values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo14(name) values('David'); Query OK, 1 row affected (0.18 sec) mysql> insert into demo14(name) values('David'); Query OK, ... 阅读更多
424 次查看
要获取初始值,请使用 left() 以及 substring_index() 的概念。让我们创建一个表:mysql> create table demo13 −> ( −> full_name varchar(100), −> short_name varchar(20) −> ); Query OK, 0 rows affected (1.18 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo13(full_name) values('John Smith'); Query OK, 1 row affected (0.27 sec) mysql> insert into demo13(full_name) values('David Miller'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo13(full_name) values('Chris Brown'); Query OK, 1 row affected (0.28 sec)使用 select 语句显示表中的记录:mysql> select *from demo13;这 ... 阅读更多
210 次查看
以下是使用 INTERVAL 与 Java - MySQL 添加月份的语法。String query; query = "insert into yourTableName values(curdate()+interval howManyNumberOfMonths month)";以下是当前日期:mysql> select curdate(); +------------+ | curdate() | +------------+ | 2020-10-25 | +------------+ 1 row in set (0.00 sec)让我们创建一个表:mysql> create table demo12 −> ( −> created_date date −> ); Query OK, 0 rows affected (1.84 sec)这里,我将从 Java 中将 2 个月添加到当前日期。现在,日期将插入到表 2020-12-25 中。Java 代码如下示例import java.sql.Connection; import java.sql.DriverManager; import com.mysql.jdbc.Statement; public ... 阅读更多
152 次查看
要获取子字符串,请在 MySQL 中使用 substr() 方法,如下面的语法所示:select substr(yourColumnName, startIndex, endIndex) from yourTableName limit anyValue; select substr(yourColumnName, startIndex+endIndex) from yourTableName limit anyValue;让我们创建一个表:mysql> create table demo11 −> ( −> id int NOT NULL AUTO_INCREMENT PRIMARY KEY, −> fileLocation text −> ); Query OK, 0 rows affected (2.60 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo11(fileLocation) values('E:/users/program/sample.sql'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo11(fileLocation) values('E:/users/data/db.sql'); Query OK, 1 row affected (0.32 sec) mysql> insert ... 阅读更多
2K+ 次查看
是的,为此,请使用 Java 中的 ArrayList 概念。语法如下:ArrayList anyVariableName= new ArrayList();让我们创建一个表:mysql> create table demo10 −> ( −> id int not null auto_increment primary key, −> name varchar(20) −> ); Query OK, 0 rows affected (2.19 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo10(name) values('John'); Query OK, 1 row affected (0.23 sec) mysql> insert into demo10(name) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo10(name) values('David'); Query OK, 1 row affected (0.13 sec)显示来自 ... 阅读更多
290 次查看
要合并,请使用简单的连接。以下是语法:select aliasName1.yourColumnName1, aliasName1.yourColumnName2, . . .N aliasName2.yourColumnName1 from yourTableName1 aliasName1 . . . N join yourTableName2 aliasName2 on yourCondition;让我们创建一个表:mysql> create table demo8 −> ( −> id int, −> name varchar(20) −> ); Query OK, 0 rows affected (1.77 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo8 values(100, 'John'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo8 values(101, 'Mike'); Query OK, 1 row affected (0.16 sec) mysql> insert into demo8 values(102, 'Bob'); Query OK, ... 阅读更多
88 次查看
为此,请使用 GROUP BY 以及 ORDER BY:select yourColumnName, count(*) as anyAliasName from yourTableName group by yourColumnName order by yourColumnName;让我们创建一个表:mysql> create table demo7 −> ( −> id int NOT NULL AUTO_INCREMENT, −> first_name varchar(50) −> , −> primary key(id) −> ); Query OK, 0 rows affected (1.22 sec)在表的帮助下插入一些记录插入命令:mysql> insert into demo7(first_name) values('John'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo7(first_name) values('David'); Query OK, 1 row affected (0.22 sec) mysql> insert into demo7(first_name) values('John'); Query OK, 1 row affected ... 阅读更多
605 次查看
要消除 LOCK TABLES 查询,您需要使用 UNLOCK TABLES。让我们创建一个表 -mysql> create table demo6 -> ( -> country_name varchar(100 -> ) -> ); Query OK, 0 rows affected (1.51 sec)使用 insert 命令将一些记录插入表中 -mysql> insert into demo6 values('US'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo6 values('UK'); Query OK, 1 row affected (0.08 sec) mysql> insert into demo6 values('AUS'); Query OK, 1 row affected (0.11 sec)使用 select 语句显示表中的记录 -mysql> select *from demo6;这将产生... 阅读更多