Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL的基础操作 (2023-07-11) #45

Open
yaogengzhu opened this issue Jul 11, 2023 · 2 comments
Open

SQL的基础操作 (2023-07-11) #45

yaogengzhu opened this issue Jul 11, 2023 · 2 comments
Labels

Comments

@yaogengzhu
Copy link
Owner

笛卡尔积

select * from height_grades, player;

等值连接

select * from player, team where player.team_id = team.team_id;

非等值连接

select
    p.player_name as name,
    p.height, h.height_level
from player as p, height_grades as h
where p.height between h.height_lowest and h.height_highest
order by p.height desc;

外连接

左连接:指的是左边的是主表

SELECT * FROM player LEFT JOIN team on player.team_id = team.team_id;
select * from player left join player_score on player.player_id = player_score.player_id;

同理 右连接表示右边是主表

select * from player, team where player.team_id(+) = team.team_id; # (+)表示主表
select * from player right join team on player.team_id = team.team_id;

自连接

select b.player_name, b.height from player as a , player as b where a.player_name = '布雷克-格里芬' and a.height < b.height
@yaogengzhu
Copy link
Owner Author

如何快速的拷贝一个表

第一步:复制表的结构

create table new_table Like origin_table

第一步:拷贝数据

insert into new_table select * from origin_table

@yaogengzhu
Copy link
Owner Author

yaogengzhu commented Jul 4, 2024

解决唯一索引,值不能重复的问题

删除唯一索引

drop index command_id on command_task;

创建非唯一索引

create index command_id on command_task (command_id);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant