select [distinct] [top n] *| 字段1 as 别名1 ,字段2 as 别名2 ,from 表1,表2 [where 条件 ] [group by 字段 [having 条件] ] [order by 字段 [asc] [desc ] ];
distinct (字段数据去重)
top n 前 n 条记录
where 条件 where 字段=“条件”
where 字段 in (“条件1”,“条件2”)
where 字段 like " *条件* "
where 字段 between 1000 and 2000
where 字段 > 1000 and | or <2000
[group by 字段 [having 条件]
例: having avg (工资) >1000
分组设条件 用 having 不用where
<,> ,=,<=,>=,<> ,mod ,^ null, not null
多表查询 注意表间关系
select 表1.表1字段1 as 别名1 ,表1.表1字段2 as 别名2 ,表2.表2字段1from 表1,表2 where 表1.表1字段 = 表2.表2字段 [group by ][order by];
子查询 select 字段1 as 别名1 ,字段2 as 别名2 ,from 表1, where 字段 = “条件” and any |all |(select from 表1 where 。。。)
union
身份证号取年龄
岁: DateDiff("yyyy", DateSerial(Mid([身份证号],7,4),Mid([身份证号],11,2),Mid([身份证号],13,2)),Now())
。Access里执行left join联合查询,总是提示:至少一个参数未指定的错误,突然想起来access中多表联合查询的sql语句比较变态,就抄来高手的文章备忘,希望对和我一样的苦逼程序员有所帮助。
首先,每次联合查询都需要用圆括号括起来:
SELECT * FROM (aa LEFT JOIN bb ON aa.a = bb.a ) LEFT JOIN cc ONcc.a = bb.a;
注意:在使用join语句查询时,如果有加多个On条件,必须用括号括起来,如:
SELECT * FROM (aa LEFT JOIN bb ON aa.a=bb.a) LEFT JOIN cc ON(bb.a=cc.a and bb.b=cc.b)
其他例子可以参考:
1、SELECT * FROM URL as a LEFT OUTER JOIN MobileAfter as b ON a.URL = b.URL
2、SELECT * FROM (URL as a LEFT OUTER JOIN MobileAfter as b ON a.URL= b.URL) LEFT OUTER JOIN MobileBefore as c ONc.URL=a.URL
3、SELECT * INTO Ttable1 FROM ((((URL as a
LEFT OUTER JOIN MobileAfter as b ON a.URL=b.URL)
LEFT OUTER JOIN MobileBefore as c ON c.URL=a.URL)
LEFT OUTER JOIN TeleCOM as d ON d.URL=a.URL)
LEFT OUTER JOIN UniCOM as e ON e.URL=a.URL)