Posted on 2006-11-06 21:41
团队精神 阅读(199)
评论(0) 编辑 收藏
-
添加数据:insert into 表名 (<列名列表> values (<值列表>));或insert into 表名 (<列名列表> select<select语句>;
-
更改已有数据: update 表名 set <新列值列表> where <过滤条件>;删除的东西可用rollback;回滚恢复. 但是truncate table 表名;删除了的数据不写入记录日志,虽然用起来比较快,但是不能被回滚.
-
数据查询:
返回所有列:select *from 表名;
指定目标数据库: select * from 数据库名.表名;--mysql
select * from 用户名.表明; --ORACLE
返回单列; select 列名 from 表名;
返回多列: select 列A,列B,列C from 表名;
事业别名: select 列A AS A,列B AS B,列C AS C from 表名 AS T;
-
排序: select 列A,列B,列C from 表名 order by 列A; 默认为升序--ASC. 降序在后面加DESC.
-
排除重复数据: select distinct 列A from 表名;
-
数据分组: 4)select 列A,3)聚合函数 from 表名
2)where 过滤条件
1)group by 列A;(数字为命令执行顺序)
-
HAVING语句: select 列A,聚合函数 from 表名
where 过滤条件
group by 列A;
having 有关聚合函数的过滤条件;(先执行group by 和where再执行聚合函数再执行having 语句).