找到 4379 篇文章 适用于 MySQL
441 次浏览
为此,使用 UNION ALL 以及 SUM()。让我们创建 5 个表 -mysql> create table DemoTable1977 ( UP int ); Query OK, 0 rows affected (0.00 sec) mysql> insert into DemoTable1977 values(10); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1977 values(20); Query OK, 1 row affected (0.00 sec) mysql> select * from DemoTable1977; +------+ | UP | +------+ | 10 | | 20 | +------+ 2 rows in set (0.00 sec) mysql> create table DemoTable1978 ( UP int ); Query OK, 0 rows affected (0.00 sec) mysql> ... 阅读更多
1K+ 次浏览
为此,使用 IF() 和 IS NULL 属性。让我们首先创建一个表 -mysql> create table DemoTable1976 ( FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1976 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1976 values('John', NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1976 values(NULL, 'Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1976 values('Chris', 'Brown'); Query OK, 1 row affected (0.00 sec)显示表中的所有记录 ... 阅读更多
181 次浏览
让我们首先创建一个表 -mysql> create table DemoTable1975 ( StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1975 values('John', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1975 values('Chris', 67); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1975 values('David', 59); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1975 values('Bob', NULL); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1975;这 ... 阅读更多
453 次浏览
为此,使用预处理语句。让我们首先创建一个表 -mysql> create table DemoTable1973 ( StudentId int, StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1973 values(101, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1973 values(102, 'John Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1973 values(103, 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1973 values(104, 'John Smith'); Query OK, 1 row affected (0.00 sec)使用 ... 阅读更多
375 次浏览
让我们首先创建一个表 -mysql> create table DemoTable1972 ( Section char(1), StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1972 values('D', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1972 values('B', 'David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1972 values('A', 'Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1972 values('C', 'Carol'); Query OK, 1 row affected (0.00 sec)使用 select 语句显示表中的所有记录 -mysql> select * from DemoTable1972;这 ... 阅读更多
3K+ 次浏览
让我们首先创建一个表 -mysql> create table DemoTable1971 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentPassword int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1971(StudentName, StudentPassword) values('John', '123456'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1971(StudentName, StudentPassword) values('Chris', '123456'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1971(StudentName, StudentPassword) values('David', '123456'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1971(StudentName, StudentPassword) values('Mike', '123456'); Query OK, 1 row affected (0.00 sec)显示所有 ... 阅读更多
81 次浏览
让我们首先创建一个表 -mysql> create table DemoTable1969 ( BranchCode varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1969 values('CSE 101'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1969 values('CSE 11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1969 values('CSE 15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1969 values('CSE 6'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1969 values('CSE 201'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... 阅读更多
169 次浏览
要仅为前 3 个值设置特定值,您需要使用 LIMIT 3。让我们首先创建一个表 -mysql> create table DemoTable1968 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1968(Name) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Sam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Mike'); Query OK, 1 ... 阅读更多
109 次浏览
为此,您可以使用 INSERT INTO SELECT 语句以及 LPAD()。让我们首先创建一个表 -mysql> create table DemoTable1967 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserId varchar(20) ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1967(UserId) select LPAD(COALESCE(MAX(id), 0) + 1, 3, '0') from DemoTable1967; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1967(UserId) select LPAD(COALESCE(MAX(id), 0) + 1, 3, '0') from DemoTable1967; Query OK, 1 row affected (0.00 sec) ... 阅读更多
1K+ 次浏览
让我们首先创建一个表 -mysql> create table DemoTable1966 ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20), PhotoLiked int ); Query OK, 0 rows affected (0.00 sec)使用 insert 命令在表中插入一些记录 -mysql> insert into DemoTable1966(UserName, PhotoLiked) values('Chris', 57); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1966(UserName, PhotoLiked) values('David', 100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1966(UserName, PhotoLiked) values('Mike', 68); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1966(UserName, PhotoLiked) values('Sam', 78); Query OK, 1 row affected (0.00 sec)显示所有 ... 阅读更多