一个小时入门sql 笔记+代码 (上)

版权声明:本文由lianyhai编写,不得用于商业用途,其他用途请随便。如果非要用做商业用途请给我微信打一下钱谢谢!哈哈哈哈 https://blog.csdn.net/qq_36303521/article/details/88197519

sqlbolt 练习sql的网站
sqlbolt.com

查询命令:
select col from table where condition
when col= * this means all col are selected
condition contains
常见运算符号
between …and …
not between…and…
in(…)
not in(…)
for example:
select * from table where id=6这就是说查询所有id等于6的行
SELECT * FROM movies where year not between 2000 and 2010;查询所有年份不在2000-2010的行

字符运算符合
在这里插入图片描述
注意_和%的区别,%是任意一个字符而_是一个字符

排序和过滤

select distinct column from table where

选择不重复的列名

order by col asc/desc

对列排序 升序或者降序
limit num offset num
限制返回的行数 offset设置哪里开始计算

合并表格 joins

inner join

SELECT column, another_table_column, …
FROM mytable
INNER JOIN another_table 
    ON mytable.id = another_table.id
WHERE condition(s)
ORDER BY column, … ASC/DESC
LIMIT num_limit OFFSET num_offset;

显然合并表格放在from后面where前面
注意名字对应要再表格中找到

outer join

区别嘛,简单来说就是交集和并集
inner呢就是取相交的部分
outer呢就是都取

表达式

可以再select col as new_col
or
where col这里进行表达式转化。

猜你喜欢

转载自blog.csdn.net/qq_36303521/article/details/88197519