例:create database samp_db character set gbk;
1.select 某列 from table;
2.select distinct 某列 from table; 列出不同(distinct)的值。
3.select 列名称 from 表名称 where 列 运算符 值;条件查询(运算符:= <> >=
between like)
4.select * from table where name='asdf'and id=1;and运算符实例
5.select * from table where (name='dasdf' or id=23) and a_id='23';or
+and混合运算符
6.select * from table order by 列名称; order by 排序
7.insert into table values ('值','值' ,'值','值');插入新的行
8.insert into table (列名称,列名称) values ('值','值');给指定列插入数据
9.update table set 列名称=新值,列名称=新值 where id=2; Update修改表中的
数据。
10.delete from table where id=1; 删除某行
11.delete from table;删除所有行
SQL 高级语法
12.select * from table limit 5;取5条
13.select top 2 * from table;取前两条
14.select top 50 percent * from table;取50%数据
15.select * from table where 列名称 like 'n%';"%" 可用于定义通配符(模式
中缺少的字母)。%:替代一个或多个字符。_:仅替代一个字符.
16.select * from table where id in (1,2,3,4); IN 操作符
17.select * from table where id between BETWEEN 操作符
18.select * from table_name as alias_name; SQL Alias(别名)
19.select a.id,a.name,b.time from table1 as a left join table2 as b
where a.id=b.uid oder by a,id desc;
19.SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Customer;GROUP BY分组
20.select * from table where address is null; SQL 的 NULL 值查询
21.select name a*(b + ifnull(c,0)) as num from table;
22.select avg(volumn_name) from table;
22.select count(column_name) from table;
COUNT(column_name) 函数返回指定列的值的数目(NULL 不计入)
23.select count(*) from table; null计入;
24.select first(column_name) from table;//第一条数据
25.select last(column_name) from table;//最后一条数据
26.select name format(time,'YYYY-MM-DD') as time from table;