找到 4379 篇文章 适用于 MySQL
160 次浏览
让我们首先创建一个表 -mysql> create table DemoTable783 ( FirstName varchar(100) ); Query OK, 0 rows affected (0.65 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable783 values('Adam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable783 values('Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable783 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable783 values('Adam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable783 values('Adam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable783 values('Robert'); Query OK, 1 ... 阅读更多
462 次浏览
为此,使用 GROUP BY HAVING 子句。让我们首先创建一个表 -mysql> create table DemoTable782 ( Name varchar(100), Score int ); Query OK, 0 rows affected (1.18 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable782 values('John', 156); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable782 values('Carol', 250); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable782 values('Bob', 140); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable782 values('John', 126); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable782 values('John', ... 阅读更多
1K+ 次浏览
让我们首先创建一个表 -mysql> create table DemoTable781 ( Name varchar(100) ); Query OK, 0 rows affected (0.66 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable781 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable781 values(''); Query OK, 1 ... 阅读更多
332 次浏览
要排除某些列名,请使用 NOT IN。让我们首先创建一个表 -mysql> create table DemoTable780 ( CustomerId int, CustomerName varchar(100), CustomerAge int, CustomerCountryName varchar(100), isMarried tinyint(1) ); Query OK, 0 rows affected (0.47 sec)以下是排除结果的查询 -mysql> select group_concat(column_name) from `information_schema`.`COLUMNS` m where table_schema = 'web' and table_name = 'DemoTable780' and column_name not in ('CustomerId','CustomerCountryName') group by table_schema,table_name;这将产生以下输出 -+------------------------------------+ | group_concat(column_name) | +------------------------------------+ | CustomerName,CustomerAge,isMarried | +------------------------------------+ 1 row in set (0.01 sec)
148 次浏览
由于列值“ADD”已经是保留字,因此您需要在 ADD 周围使用反引号,例如`ADD`。让我们看一个示例并创建一个表 -mysql> create table DemoTable779 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, `ADD` int ); Query OK, 0 rows affected (0.47 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable779(`ADD`) values(54); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable779(`ADD`) values(89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable779(`ADD`) values(66); Query OK, 1 row affected ... 阅读更多
183 次浏览
让我们首先创建一个表 -mysql> create table DemoTable778 ( ClientId varchar(100), ClientName varchar(100) ); Query OK, 0 rows affected (1.05 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable778 values('J-101', 'John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable778 values('A-102', 'Adam'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable778 values('C-103', 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable778 values('D-104', 'David'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable778 values('R-105', 'Robert'); Query OK, 1 row affected ... 阅读更多
60 次浏览
让我们首先创建一个表 -mysql> create table DemoTable777 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (1.34 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable777(StudentName, StudentAge) values('Chris', 23); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable777(StudentName, StudentAge) values('Robert', 21); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable777(StudentName, StudentAge) values('Mike', 19); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable777(StudentName, StudentAge) values('Bob', 22); Query OK, 1 row ... 阅读更多
3K+ 次浏览
假设您已将列值设置为唯一键,并尝试在表中插入重复值。这将导致 ERROR 1062 (23000):Duplicate entry。让我们首先创建一个表 -mysql> create table DemoTable776 ( FirstValue int, SecondValue int, unique key(FirstValue, SecondValue) ); Query OK, 0 rows affected (0.74 sec)使用 insert 命令在表中插入一些记录。在插入重复值时,会出现与下面显示的相同的错误 -mysql> insert into DemoTable776 values(10, 20); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable776 values(10, 40); Query OK, 1 row affected (0.15 ... 阅读更多
296 次浏览
让我们首先创建一个表 -mysql> create table DemoTable775 ( FirstName varchar(100) ); Query OK, 0 rows affected (0.78 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable775 values('Adam') ; Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable775 values('Carol'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable775 values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable775 values('Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable775 values('Adan'); Query OK, 1 row affected (0.15 sec)使用 select 语句显示表中的所有记录 -mysql> select ... 阅读更多
8K+ 次浏览
当前日期格式为“YYYY-mm-dd”。要更改当前日期格式,您可以使用 date_format()。让我们首先显示当前日期 -mysql> select curdate();这将产生以下输出 -+------------+ | curdate() | +------------+ | 2019-08-08 | +------------+ 1 row in set (0.00 sec)以下是更改 curdate()(当前日期)格式的查询 -mysql> select date_format(curdate(), '%m/%d/%Y');这将产生以下输出 -+------------------------------------+ | date_format(curdate(), '%m/%d/%Y') | +------------------------------------+ | 08/08/2019 | +------------------------------------+ 1 row in set (0.00 sec)让我们首先创建一个表 -mysql> create table DemoTable ... 阅读更多