MySQL

记录一些LeetCode上的SQL题目

基础语法知识

关键字

between:字面意思,和and连用

in:和python的in一样

distinct:选取的列中值一样的列只显示一个

is null:字面意思,和python的is none一样

count:统计符合条件的项数,和Python的count函数一样

like:还是字面意思,匹配一个模式的字符串,通常随通配符联用,%代表0到无限匹配字符,_代表匹配任意一个字符一次

not like:跟上面反的呗

sum:求和

avg:求平均数

min:最小值

max:最大值

as:跟Python里面一样,相当于变量改名

order by:根据某个列的值排序

desc:反向排序关键字

group by:将同一列中的同样值的行聚合在一起

limit:限制取出行数的数量

aggregate function不能在where里面使用,而having下面可以使用且起到想要的效果

join on:对两张不同的表中的某一列的值进行比较

inner join: Inner join will combine rows from different tables if the join condition is true

left join: Outer joins also combine rows from two or more tables, but unlike inner joins, they do not require the join condition to be met. Instead, every row in the _left _table is returned in the result set, and if the join condition is not met, then NULLvalues are used to fill in the columns from the _right _table. 简而言之即左边表项全部纳入结果,右边表项在on条件里不符合的全部设为null值

results matching ""

    No results matching ""