找到 4379 篇文章 关于 MySQL
892 次查看
让我们创建一个表 -mysql> create table DemoTable1923 ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1923(UserId, UserName) select 101 as UserId, 'Chris' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) select 102 as UserId, 'Robert' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) ... 阅读更多
174 次查看
让我们创建一个表 -mysql> create table DemoTable1922 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1922(StudentName) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Robert'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Mike'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1922;这 ... 阅读更多
126 次查看
对于随机行,您可以使用 RAND(),而要修复特定列,请使用 ORDER BY 子句。让我们创建一个表 -mysql> create table DemoTable1921 ( Number int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1921 values(40); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(80); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(820); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(10); Query OK, 1 row affected (0.00 sec)显示所有记录 ... 阅读更多
9K+ 次查看
要对成绩进行分组,请使用 MySQL GROUP BY。要进行求和,请使用 MySQL sum()函数。让我们首先创建一个表 -mysql> create table DemoTable1920 ( StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1920 values('Chris', 67); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('David', 97); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('Chris', 57); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('David', 45); Query OK, 1 row affected (0.00 sec) mysql> ... 阅读更多
483 次查看
您可以在存储过程中使用 DECLARE。语法如下 -declare yourVariableName yourDataType;为了理解以上语法,让我们创建一个存储过程:mysql> delimiter // mysql> create procedure square_demo(in Value int) begin declare magicValue int; set magicValue=Value; select concat('Your Square Value=',magicValue*magicValue) as Output; end ; // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;现在您可以使用 call 命令调用存储过程 -mysql> call square_demo(15);这将产生以下输出 -+-----------------------+ | Output | +-----------------------+ | Your Square Value=225 | +-----------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
3K+ 次查看
要修复此错误,让我们看看如何正确创建用户。让我们创建一个用户 -mysql> create user 'Emma'@'localhost' IDENTIFIED BY 'emma_654'; Query OK, 0 rows affected (0.00 sec)让我们显示所有用户及其主机 -mysql> select user, host from MySQL.user;这将产生以下输出。上面创建的新用户在下面所有用户及其主机的列表中可见 -+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie ... 阅读更多
71 次查看
为此,您可以使用 UNION ALL 以及 WHERE NOT EXISTS 并实现 NOT IN 来忽略表中已有的值。使用 SELECT 和 UNION ALL 添加表中尚不存在的值。让我们首先创建一个表 -mysql> create table DemoTable1918 ( Value int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1918 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1918 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into ... 阅读更多
129 次查看
要获取除第一行和最后一行之外的所有行,请使用子查询以及 MIN() 和 MAX()。让我们首先创建一个表 -mysql> create table DemoTable1917 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentCode int, StudentMarks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1917(StudentCode, StudentMarks) values(78, 95); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1917(StudentCode, StudentMarks) values(78, 96); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1917(StudentCode, StudentMarks) values(78, 97); Query OK, 1 row affected (0.00 ... 阅读更多
137 次查看
为此,使用 MySQL CASE 语句设置条件 -mysql> create table DemoTable1916 ( StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1916 values('Chris', 59); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('David', 89); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('Sam', 94); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('Mike', 75); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1916 values('Carol', 69); Query OK, 1 row affected ... 阅读更多
221 次查看
要设置 NOT NULL,请使用 IS NOT NULL 并查找该值。语法如下 -select if('' is not NULL, 1, 0) as anyAliasName;以下是工作查询 -mysql> select if('' is not NULL, 1, 0);这将产生以下输出 -+------------------------+ | if('' is not NULL, 1, 0) | +------------------------+ | 1 | +------------------------+ 1 row in set (0.00 sec)为了理解以上语法,让我们创建一个表 -mysql> create table DemoTable1915 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert ... 阅读更多