sql 经典语句记录
Vb具有强大的数据库处理能力.这些都和他能处理sql语句有关.
再使用sql语句的时候.我们需要掌握他的基本格式.下面我总结了一下常见的sql语句
关键字 |
作用 |
格式 |
Select |
将资料从数据库中的表格内选出 |
SELECT "栏位名" FROM "表格名" |
distinct |
找出表格内的不同资料值的情况 |
SELECT DISTINCT "栏位名" FROM "表格名" |
where |
选择性地抓资料 |
SELECT "栏位名" FROM "表格名" WHERE "条件" |
And,or |
复杂条件是由二或多个简单条件透过 AND 或是 OR 的连接而成 |
SELECT "栏位名" FROM "表格名" WHERE "简单条件" {[AND|OR] "简单条件"}+ |
In |
将知道的值都放入IN 这个子句 |
SELECT "栏位名" FROM "表格名" WHERE "栏位名" IN ('值一', '值二', ...) |
Between |
可以运用一个范围 (range) 内抓出数据库中的值 |
SELECT "栏位名" FROM " 表格名" WHERE "栏位名" BETWEEN '值一' AND '值二' |
Like |
依据一个套式 (pattern) 来找出我们要的资料 |
SELECT "栏位名" FROM "表格名" WHERE "栏位名" LIKE {套式} |
Order by |
由小往大 (ascending) 或是由大往小(descending)排序 |
SELECT "栏位名" FROM "表格名" [WHERE "条件"] ORDER BY "栏位名" [ASC, DESC] |
Count |
能够数出在表格中有多少笔资料被选出来 |
SELECT COUNT("栏位名") FROM "表格名" |
Group by |
分类汇总 |
SELECT "栏位1", SUM("栏位2") FROM "表格名" GROUP BY "栏位1" |
Having |
对函数产生的值来设定条件 |
SELECT "栏位1", SUM("栏位2") FROM "表格名" GROUP BY "栏位1" HAVING (函数条件) |
Alias |
别名 |
SELECT "表格别名"."栏位1" "栏位别名" FROM "表格名" "表格别名" |