找到 4379 篇文章 关于 MySQL
977 次浏览
为此,使用聚合函数 SUM()。在此方法中,将行值相乘。让我们先创建一个表 -mysql> create table DemoTable( ProductQuantity int, ProductPrice int ); Query OK, 0 rows affected (0.48 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(10, 9); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(6, 20); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(7, 100); Query OK, 1 row affected (0.08 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;这将产生以下 ... 阅读更多
877 次浏览
为此,使用 GROUP BY 子句以及聚合函数 SUM()。让我们先创建一个表 -mysql> create table DemoTable( Name varchar(100), Score int ); Query OK, 0 rows affected (0.70 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('Adam', 50); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob', 80); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Adam', 70); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Adam', 10); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Carol', ... 阅读更多
133 次浏览
让我们先创建一个表 -mysql> create table DemoTable( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100) ); Query OK, 0 rows affected (0.51 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable(CustomerName) values('Adam Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(CustomerName) values('Chris Brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(CustomerName) values('David Miller'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(CustomerName) values('Carol Taylot'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(CustomerName) values('Carol Taylor'); Query OK, 1 row affected ... 阅读更多
6K+ 次浏览
为此,可以使用 CASE 语句。让我们先创建一个表 -mysql> create table DemoTable( Id int, Value int ); Query OK, 0 rows affected (0.51 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values(10, 100); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(10, -110); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(10, 200); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(10, -678); Query OK, 1 row affected (0.17 sec)使用 select 语句显示表中的所有记录 -mysql> ... 阅读更多
417 次浏览
让我们先创建一个表 -mysql> create table DemoTable( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeName varchar(100), JoiningDate date ); Query OK, 0 rows affected (0.48 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable(EmployeeName, JoiningDate) values('Chris', '2019-01-21'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(EmployeeName, JoiningDate) values('Robert', '2016-12-01'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(EmployeeName, JoiningDate) values('Mike', '2015-03-12'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;这将产生以下输出 -+------------+--------------+-------------+ ... 阅读更多
5K+ 次浏览
让我们先创建一个表 -mysql> create table DemoTable( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) ); Query OK, 0 rows affected (0.47 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Name) values('Adam'); Query OK, 1 row affected (0.28 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;这将产生以下输出 -+----+------+ | Id | Name | +----+------+ | 1 | ... 阅读更多
2K+ 次浏览
如果一行匹配,则语句 SELECT TRUE 返回 1。让我们先创建一个表 -mysql> create table DemoTable(Name varchar(100)); Query OK, 0 rows affected (0.54 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.12 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;这将产生以下输出 -+--------+ | Name | +--------+ | Chris | | Robert ... 阅读更多
209 次浏览
让我们先创建一个表 -mysql> create table DemoTable(GetSundayDate date); Query OK, 0 rows affected (0.44 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable values('2019-08-07'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2018-09-05'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-09-12'); Query OK, 1 row affected (0.17 sec)使用 select 语句显示表中的所有记录 -mysql> select *from DemoTable;这将产生以下输出 -+---------------+ | GetSundayDate | +---------------+ | 2019-08-07 | | 2018-09-05 | | 2019-09-12 | +---------------+ 3 rows in ... 阅读更多
670 次浏览
要将 varchar 转换为无符号整数,请使用 CAST() 函数。让我们先创建一个表 -mysql> create table DemoTable868(Amount varchar(100)); Query OK, 0 rows affected (0.51 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable868 values('781'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable868 values('990'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable868 values('1002'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable868 values('560'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable868 values('890'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable868 values('9890'); ... 阅读更多
1K+ 次浏览
为此,使用 LIMIT 和 OFFSET。让我们先创建一个表 -mysql> create table DemoTable867(EmployeeSalary int); Query OK, 0 rows affected (0.64 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable867 values(63737); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable867 values(899833); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable867 values(23644); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable867 values(89393); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable867 values(534333); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable867 values(889322); Query OK, 1 ... 阅读更多