找到 4219 篇文章 关于 MySQLi
665 次浏览
要在 MySQL 中创建空视图,以下是语法:create or replace view yourViewName as select yourValue AS yourColumnName, yourValue AS yourColumnName2, . . N from dual where false;让我们实现上述语法,以便在 MySQL 中创建空视图:mysql> create or replace view empty_view as select "John Smith" AS ClientName, "US" AS ClientCountryName, false AS isMarried from dual where false; Query OK, 0 rows affected (0.20 sec)让我们检查视图的描述:mysql> desc empty_view;这将产生以下输出:-+-------------------+-------------+------+-----+---------+-------+ | Field ... 阅读更多
3K+ 次浏览
使用 DEFAULT CURRENT_TIMESTAMP 和 ON UPDATE CURRENT_TIMESTAMP,列将具有当前时间戳作为其默认值,并且会自动更新为当前时间戳。让我们看一个例子并创建一个表:mysql> create table DemoTable737 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAdmissiondate datetime ); Query OK, 0 rows affected (0.68 sec)以下是 MySQL 中 CURRENT_TIMESTAMP 和 ON UPDATE CURRENT_TIMESTAMP 的查询:mysql> alter table DemoTable737 modify column StudentAdmissiondate timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; Query OK, 0 rows affected (2.20 sec) Records: 0 Duplicates: 0 Warnings: 0Let ... 阅读更多
1K+ 次浏览
要更新所有条目,同时忽略单个值,您需要使用 IF()。让我们首先创建一个表:mysql> create table DemoTable736 ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100), isMarried boolean ); Query OK, 0 rows affected (0.53 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable736(CustomerName, isMarried) values('Chris', 0); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable736(CustomerName, isMarried) values('Robert', 0); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable736(CustomerName, isMarried) values('David', 0); Query OK, 1 row affected (0.24 sec) mysql> insert into ... 阅读更多
49 次浏览
让我们首先创建一个表:mysql> create table DemoTable(EmployeeCode varchar(100)); Query OK, 0 rows affected (0.56 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('EMPLOYEE:100 John Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('EMPLOYEE:16537 Chris Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('EMPLOYEE:100 David Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('EMPLOYEE:100 23432 David Miller'); Query OK, 1 row affected (0.20 sec)使用 select 语句显示表中的所有记录:mysql>; select *from DemoTable;这将产生以下输出 ... 阅读更多
4K+ 次浏览
要在 MySQL 中合并行,请使用 GROUP_CONCAT()。让我们首先创建一个表:mysql> create table DemoTable734 ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.73 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable734 values(101, 'John'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable734 values(102, 'John'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable734 values(103, 'Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable734 values(104, 'Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable734 values(104, 'Chris'); Query OK, 1 row affected ... 阅读更多
127 次浏览
让我们首先创建一个表:mysql> create table DemoTable732 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PassengerId int, PassengerName varchar(100), PassengerAge int, PassengerTravelDatetime datetime ); Query OK, 0 rows affected (0.67 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable732(PassengerId, PassengerName, PassengerAge, PassengerTravelDatetime) values(110, 'Chris', 25, '2019-07-23 12:45:56'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable732(PassengerId, PassengerName, PassengerAge, PassengerTravelDatetime) values(120, 'Robert', 24, '2019-07-21 11:05:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable732(PassengerId, PassengerName, ... 阅读更多
699 次浏览
要从 MySQL 表中删除多个条目,请使用 JOIN。让我们首先创建一个表:mysql> create table DemoTabl(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100)); Query OK, 0 rows affected (0.69 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(FirstName) values('Bob'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(FirstName) values('Mike'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(FirstName) values('Adam'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable(FirstName) values('Bob'); Query OK, 1 row ... 阅读更多
2K+ 次浏览
让我们首先创建一个表:mysql> create table DemoTable731 (Value varchar(100)); Query OK, 0 rows affected (0.50 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable731 values('4.50'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable731 values('7.83'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable731 values('8.91'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable731 values('560.34'); Query OK, 1 row affected (0.21 sec)使用 select 语句显示表中的所有记录:mysql> select *from DemoTable731;这将产生以下输出:-+--------+ | Value | +--------+ | 4.50 ... 阅读更多
742 次浏览
要计算日期范围内的天数,您需要使用 DATEDIFF() 查找日期之间的差值。让我们首先创建一个表:mysql> create table DemoTable730 ( StartDate date, EndDate date ); Query OK, 0 rows affected (0.45 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable730 values('2019-01-21', '2019-07-21'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable730 values('2018-10-11', '2018-12-31'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable730 values('2016-01-01', '2016-12-31'); Query OK, 1 row affected (0.14 sec)使用 select 语句显示表中的所有记录:mysql> select *from DemoTable730;这将产生以下 ... 阅读更多
1K+ 次浏览
为此,使用存储过程。让我们首先创建一个表:mysql> create table DemoTable(Id int, Name varchar(100)); Query OK, 0 rows affected (1.51 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(11, 'Chris'); Query OK, 1 row affected (0.41 sec)使用 select 语句显示表中的所有记录:mysql> select *from DemoTable;这将产生以下输出:-+------+-------+ | Id | Name | +------+-------+ | 10 | John | | 11 | Chris | +------+-------+ 2 rows ... 阅读更多