1.查询
查询所有
select * from emp;
查询几列
select name,sex,age from emp;
2.算术表达式
查询一年的金额
select salary*12 from emp
3.别名
select e.name,e.sex,e.age from emp as e;
4.字符串连接(将姓和名并在一列)
select last_name || ' '|| first_name from emp;
5.消除重复行
select distinct id from emp
6.条件查询(and or not)
select * from employee where id>2 and id <4;
select * from employee where id<>3;
select * from employee where id >3 or id <45;
select * from employee where id not is 4;
7.排序
select * from emp order by asc;(小到大 升序)
select * from emp order by desc;(大到小 降序)
8.统计函数
count 总数、max 最大、min最小、avg平均
select count(name)from employee;
select max(age) from employee;
select min(age) from employee;
select avg(age) from employee;
本文介绍SQL的基本操作,包括查询、算术表达式、别名使用、字符串连接、消除重复行、条件查询、排序及统计函数等核心内容。适用于初学者快速上手。
28

被折叠的 条评论
为什么被折叠?



