基本SQL小结
上一篇 / 下一篇 2007-07-12 22:58:05 / 个人分类:数据库
2[7V-~V Lg,D ?0今天对SQL的基础知识做个小结:
%m1A@&C Difd.x0@Gh1d?0 一,select
"OT_(r8a k07G:my P1V Y01,select [select_list]51Testing软件测试网?G I%k zu*H"nt
"Esh.R2O~!L1wHN0 from [table_name]51Testing软件测试网A-UQ#C.A+t
qGNl&Y~ Q j0 where [search_conditions]
rst8{2_o6]051Testing软件测试网2i,MI0n4J[ E8H5VFgroup by [group_by_list]
rA&zwWf051Testing软件测试网#Mu w!ERu(having [search_conditions])
2cGj*tld:s051Testing软件测试网I4Du A,[5?!wHZ:wporder by [order_list]51Testing软件测试网eA)I.q|o$Z q'FG
51Testing软件测试网0@7d$k}c`}h(compute [function])
u}w ~Tp U051Testing软件测试网E:h3I;|? [3IOa.where
rHH#J^`;@a.|9L0TIG C @2G5mq@0 where子句的查询条件可以包括:51Testing软件测试网q B4@%Y c)h9R jn
51Testing软件测试网@(Q~!nZ I9b比较运算符:<,>,<=,>=,=,!=,!<,!>51Testing软件测试网$t,E:V:^B._gq!s
V-`-gYa0范围说明:between A and b, not between A and b
?s` @2m6Ng0ZGf2t:\iO/X0可选值列表:in( ), not in()
}3F Xe'fs5ah0N6B%T0v{Yh Ld0模式匹配:like '_', not like'%'
`:IA;^,{$F BD;{051Testing软件测试网Zt3B'oe]是否为空值:is null, is not null51Testing软件测试网l+G4fKNT a X
51Testing软件测试网k#k#X M6O*Wj{x9wy逻辑组合:and, or, not
.\ ocl_uT0-@v*fsmk A0b.group by51Testing软件测试网T4jk9fO
0d9U+Hn$] U0 根据条件自动分组,上下分开。
B:k*yM `]~!^051Testing软件测试网0jS#l,Q[Ij(o(Ehaving子句,和group by连用,对分组指定搜索条件。51Testing软件测试网 ?tYD)GG
51Testing软件测试网KC8X.v'Feg.查询多个员工的工资不低于6000的部门编号。51Testing软件测试网2p#w"`Ws"o
MY;WGov0 select dept_id,count(*)from employee
'ha+m:S NP0eX&R.P8hAc!Y)e#T0 where e_wage>=6000
4{+?E}9[g*g+} S051Testing软件测试网kH!vt;ZL,t dU8ggroup by dept_id51Testing软件测试网5`3Me? Dg.nN#o
51Testing软件测试网:suWLCOw^!Rhaving count(*)>=1(多个)51Testing软件测试网8~,M0R]5aYGX3Y
51Testing软件测试网S3kndA0Ni9w}c.order by [orderby_conditions] [desc,asc]
Q4Oe S \6NS2\6r$l0wLCE `/W0d.function 汇总函数(针对行)|(针对列)字段之间直接进行数学计算
5I m3qu/F"PA%mK0