找到 4379 篇文章 关于 MySQL

如何在 MySQL 中查找在一个或多个列中具有精确值的行?

AmitDiwan
更新于 2019-12-26 06:48:18

376 次浏览

为此,您可以使用带有子查询的 GROUP BY HAVING。让我们首先创建一个表 -mysql> create table DemoTable1861      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Name varchar(20),      Marks int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1861(Name, Marks) values('John', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1861(Name, Marks) values('Chris', 74); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1861(Name, Marks) values('David', 89); Query OK, 1 row affected (0.00 sec) ... 阅读更多

如何在 MySQL 存储过程中使用 OUT 参数/从表中使用 SELECT 读取数据?

AmitDiwan
更新于 2019-12-26 06:46:30

476 次浏览

为此,您可以使用 SELECT INTO。让我们首先创建一个表 -mysql> create table DemoTable1860      (      Amount int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1860 values(1590); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(410); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(3000); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -Mysql> select * from DemoTable1860; 这将产生以下输出 -+--------+ | Amount ... 阅读更多

在 MySQL 存储过程中重命名表是否有简单的方法?

AmitDiwan
更新于 2019-12-26 06:44:11

190 次浏览

是的,使用带 RENAME 的 ALTER 命令。让我们首先创建一个表 -mysql> create table DemoTable1859      (      Id int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1859 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1859 values(102); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1859; 这将产生以下输出 -+------+ | Id   | +------+ |  101 | |  102 | +------+ 2 rows ... 阅读更多

查找 MySQL 中重复的列值并显示它们

AmitDiwan
更新于 2019-12-26 06:39:26

565 次浏览

为此,使用 GROUP BY HAVING 子句。让我们首先创建一个表 -mysql> create table DemoTable1858      (      ModelNumber varchar(50)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1858 values('Audi A4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi A6'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi A4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi Q5'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi R8'); ... 阅读更多

MySQL 查询以获取连字符之前的所有字符

AmitDiwan
更新于 2019-12-26 06:38:27

888 次浏览

为此,您可以使用 SUBSTRING_INDEX()。让我们首先创建一个表 -mysql> create table DemoTable1857      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1857 values('John-Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1857 values('Brown-Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1857 values('David-Carol-Miller'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1857; 这将产生以下输出 -+--------------------+ | Name   ... 阅读更多

在 MySQL 中对位字段使用 GROUP_CONCAT() 返回垃圾?如何修复?

AmitDiwan
更新于 2019-12-26 06:37:09

140 次浏览

要修复,请将 group_concat() 与列的 0 相加一起使用。让我们首先创建一个表 -mysql> create table DemoTable1856      (      Id int,      Value bit(1)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1856 values(101, 1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1856 values(102, 0); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1856 values(101, 0); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1856 values(102, 1); Query OK, 1 row affected (0.00 ... 阅读更多

哪种 MySQL 数据类型应该用于存储血型?

AmitDiwan
更新于 2019-12-26 06:35:52

865 次浏览

要存储血型,请使用 varchar(3) 或 ENUM。让我们首先创建一个表 -mysql> create table DemoTable1855      (      BloodType varchar(3)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1855 values('A+'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('A-'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('B+'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('B-'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('AB+'); Query OK, 1 row affected ... 阅读更多

使用 MySQL 获取列表中特定项目的不同数量

AmitDiwan
更新于 2019-12-26 06:34:03

154 次浏览

要查找特定项目的不同数量,请将 COUNT() 与 GROUP BY 子句一起使用。让我们首先创建一个表 -mysql> create table DemoTable1854      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1854 values('John-Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1854 values('Chris-Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1854 values('Adam-Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1854 values('John-Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... 阅读更多

使用 MySQL 在最近 50 条记录中仅选择 5 行随机行?

AmitDiwan
更新于 2019-12-26 06:31:46

323 次浏览

为此,请将 ORDER BY RAND() 与子查询一起使用。让我们首先创建一个表 -mysql> create table DemoTable1853      (      UserId int NOT NULL AUTO_INCREMENT,      PRIMARY KEY(UserId)      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1853 values(), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ... 阅读更多

为什么在 MySQL 中比较类型不会引发错误?

AmitDiwan
更新于 2019-12-26 06:30:23

99 次浏览

如果您尝试比较字符串和整数,MySQL 不会报错,因为它会将字符串转换为整数。让我们先创建一个表 -mysql> create table DemoTable1852      (      Value1 varchar(20),      Value2 int      ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1852 values('1John', 1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1852 values('John', 1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1852 values('1', 1); Query OK, 1 row affected (0.00 sec) mysql> insert into ... 阅读更多

广告
© . All rights reserved.