10-总结
查询的完整格式 ^^ 不要被吓到 其实很简单 ! !
SELECT select_expr [,select_expr,...] [
FROM tb_name
[WHERE 条件判断]
[GROUP BY {col_name | postion} [ASC | DESC], ...]
[HAVING WHERE 条件判断]
[ORDER BY {col_name|expr|postion} [ASC | DESC], ...]
[ LIMIT {[offset,]rowcount | row_count OFFSET offset}]
]
完整的select语句
select distinct *
from 表名
where ....
group by ... having ...
order by ...
limit start,count
执行顺序为:
from 表名
where ....
group by ...
select distinct *
having ...
order by ...
limit start,count
实际使用中,只是语句中某些部分的组合,而不是全部
注意事项:
sql语句都是以
分号
结尾聚合函数
常和分组
连用limit start, count
要放在sql语句的最后面mysql中建表的时候应尽量避免使用mysql保留关键字:比如desc、index等,有些框架使用的时候会报错
Last updated
Was this helpful?