找到 4379 篇文章 关于 MySQL
1K+ 阅读量
要计算 MySQL 中多个表中的行数,语法如下:Select (select count(*) from yourTableName1) as anyAliasName1, (select count(*) from yourTableName2) as anyAliasName2 from dual;让我们先创建一个表:mysql> create table DemoTable1 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.56 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1 values(), (), (), (), (), (); Query OK, 6 rows affected (0.24 sec) Records: 6 Duplicates: 0 Warnings: 0显示所有记录... 阅读更多
159 阅读量
MySQL 中与 sybase ASE 命令等效的命令是 EXPLAIN 关键字。让我们先创建一个表:mysql> create table DemoTable1531 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (2.92 sec) mysql> create index Name_index1 on DemoTable1531(StudentName); Query OK, 0 rows affected (0.99 sec) Records: 0 Duplicates: 0 Warnings: 0使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1531(StudentName) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1531(StudentName) values('Robert'); Query OK, 1 row affected (0.10 sec) mysql> insert into ... 阅读更多
96 阅读量
为此,请使用 AVG()。要查找最大平均值,请使用 MAX() 并按 id 分组。让我们先创建一个表:mysql> create table DemoTable -> ( -> PlayerId int, -> PlayerScore int -> ); Query OK, 0 rows affected (0.55 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(1, 78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(2, 82); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(1, 45); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(3, 97); ... 阅读更多
485 阅读量
为此,请使用 INSERT INTO SELECT 语句。让我们先创建一个表:mysql> create table DemoTable1 -> ( -> PersonId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> PersonName varchar(20), -> PersonAge int, -> PersonCountryName varchar(20) -> ); Query OK, 0 rows affected (0.55 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1(PersonName, PersonAge, PersonCountryName) values('Chris Brown', 24, 'US'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1(PersonName, PersonAge, PersonCountryName) values('John Doe', 26, 'UK'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1(PersonName, PersonAge, PersonCountryName) values('David ... 阅读更多
178 阅读量
让我们先创建一个表:mysql> create table DemoTable -> ( -> ClientId int, -> Value int -> ); Query OK, 0 rows affected (0.79 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values(10, 678); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20, 678); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(30, 678); Query OK, 1 row affected (0.09 sec)使用 select 语句显示表中的所有记录:mysql> select *from DemoTable;这将产生以下输出:+----------+-------+ | ClientId | Value ... 阅读更多
234 阅读量
让我们先创建一个表:mysql> create table DemoTable1528 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentSubject varchar(20) -> ); Query OK, 0 rows affected (0.53 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1528(StudentName, StudentSubject) values('Chris', 'MongoDB'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1528(StudentName, StudentSubject) values('Bob', 'MySQL'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1528(StudentName, StudentSubject) values('David', 'Java'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1528(StudentName, StudentSubject) values('Carol', 'C'); Query OK, 1 ... 阅读更多
3K+ 阅读量
要插入带双引号的记录,请使用反斜杠 (\),如下面的语法所示:语法insert into yourTableName values('\"yourValue\"');让我们先创建一个表:mysql> create table DemoTable -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.63 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable values('\"John\"'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('\"Chris\"'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('\"Adam Smith\"'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('\"Carol\"'); Query OK, 1 row affected ... 阅读更多
3K+ 阅读量
要仅显示小时和分钟,请使用 DATE_FORMAT() 并设置格式说明符,如下面的语法所示:select date_format(yourColumnName, '%H:%i') as anyAliasName from yourTableName;让我们先创建一个表:mysql> create table DemoTable1527 -> ( -> ArrivalDatetime datetime -> ); Query OK, 0 rows affected (0.76 sec)使用 insert 命令在表中插入一些记录:mysql> insert into DemoTable1527 values('2019-01-10 12:34:45'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1527 values('2018-12-12 11:00:34'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1527 values('2019-03-21 04:55:56'); Query OK, 1 row affected (0.18 sec)显示所有记录... 阅读更多
312 阅读量
让我们先创建一个表:mysql> create table DemoTable1526 -> ( -> CustomerName varchar(20), -> PurchaseDate date -> ); Query OK, 0 rows affected (0.67 sec)使用 insert 命令在表中插入一些记录。这里,我们插入了 2019 年的日期:mysql> insert into DemoTable1526 values('Adam', '2019-06-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1526 values('Sam', '2019-04-26'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1526 values('Chris', '2019-05-24'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1526 values('David', '2019-10-10'); Query OK, 1 row affected (0.23 sec) mysql> insert into ... 阅读更多
176 阅读量
要选择日期并格式化,请使用 SELECT DATE_FORMAT()。以下是语法 -语法select date_format(yourColumnName, '%e %b %y') from yourTableName;让我们先创建一个表 -mysql> create table DemoTable -> ( -> DueDate date -> ); Query OK, 0 rows affected (0.52 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-12-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-09-15'); Query OK, 1 row affected (0.07 sec)使用 select 语句显示表中的所有记录 -mysql> select *from ... 阅读更多