[root@kvm3 html]# mycli -uroot -p123qwe Connecting to socket /var/lib/mysql/mysql.sock, owned by user mysql MariaDB 10.5.16 mycli 1.26.1 Home: http://mycli.net Bug tracker: https://github.com/dbcli/mycli/issues Thanks to the contributor - Lewis Peckover
MariaDB root@(none):(none)> use dyw; You are now connected to database "dyw" as user "root" Time: 0.003s Time: 0.147s
MariaDB root@(none):dyw> create table dcount(author varchar(40) not null, dcount
-> int);
Query OK, 0 rows affected
MariaDB root@(none):dyw> insert into dcount(author,dcount) values('dywang',4),('l
-> inda',3),('peter',2),('rita',1);
Query OK, 4 rows affected
Time: 0.105s
MariaDB root@(none):dyw> select * from dcount; +--------+--------+ | author | dcount | +--------+--------+ | dywang | 4 | | linda | 3 | | peter | 2 | | rita | 1 | +--------+--------+ 4 rows in set Time: 0.045s
MariaDB root@(none):dyw> select * from tbl; +----+---------+--------+-----------------+ | id | title | author | submission_date | +----+---------+--------+-----------------+ | 1 | c++ | peter | 2023-03-30 | | 2 | Linux | linux | 2023-01-30 | | 4 | ansible | dywang | 2023-04-30 | +----+---------+--------+-----------------+ 3 rows in set Time: 0.030s
,」代替。
MariaDB root@(none):dyw> select a.id,a.author,b.dcount from tbl a JOIN dcount b w
-> here a.author=b.author;
+----+--------+--------+
| id | author | dcount |
+----+--------+--------+
| 4 | dywang | 4 |
| 1 | peter | 2 |
+----+--------+--------+
2 rows in set
Time: 0.043s
MariaDB root@(none):dyw> select a.id,a.author,b.dcount from tbl a LEFT JOIN dcoun
-> t b on a.author=b.author;
+----+--------+--------+
| id | author | dcount |
+----+--------+--------+
| 4 | dywang | 4 |
| 1 | peter | 2 |
| 2 | linux | <null> |
+----+--------+--------+
3 rows in set
Time: 0.024s
MariaDB root@(none):dyw> select a.id,a.author,b.dcount from tbl a RIGHT JOIN dcou
-> nt b on a.author=b.author;
+--------+--------+--------+
| id | author | dcount |
+--------+--------+--------+
| 1 | peter | 2 |
| 4 | dywang | 4 |
| <null> | <null> | 3 |
| <null> | <null> | 1 |
+--------+--------+--------+
4 rows in set
Time: 0.025s