计算机二级VF里,SQL语言输入的时候,什么时候用逗号,什么时候用句号怎么区分??as怎么用啊?
1个回答
展开全部
你好,刚翻了书,查下SQL语句除了有中文的句子,别的没看到有用句号的。一般的都用的是逗号,而且要特别注意,这个逗号是在输入法在英文状态下输入的,否则在开发工具中SQL语句你是无法调试成功的。
as用法:
是给现有的字段名另指定一个别名的意思,比如:
select username as 用户名,password as 密码 from users
补充:比如其中的一个好处是:当字段名是英文或拼音缩写时,采用汉字替代之后可以给阅读带来方便
sql中as的用法和一些经典的sql语句
1、delete table1 from (select * from table2) as t2 where table1.id=t2.id
2、truncate table table1 (不在事务日志中做记录,比delete table快,但不能激活触发器)
3、update table1 set column=column+1 where id=(select id from table2)
4、update table1 set column=column+1 from table1,table2 where table1.id=table2.id
5、select top n [Percent] * from table1 '输出百分比记录
6、select id,column1 * column2 as column from table1 '可算明白as的用法了
7、select * from table1 where column1 like 'SQL#_G_O' escape '#' '单匹配
8、select table1.id from table1 where not exists (select table2.id from table2 where table1.id=table2.id) '这个应该比not in快一些
9、select table1.id from table1,table2 where table1.id<>table2.id '看复合查询机制
10、select table1.id from table1,table2,(select id from table3) as t3 where table1.id=table2.id and table2.id=t3.id '有些类似[1]了......
11、select * from table1 where column1 like '[A]%' or like '[^B]%'
12、select @column1=column1 from table1;select @column1 as column1 '存储到自定义变量
13、select * from table1 where contains(column1,'char1 or char2*') '全文索引
14、select * from table1 where contains(column1,'前有 near 中有 near 后有')
15、select * from table1 where contains(column1,'formsof(inflectional,go)') '派生
16、select * from table1 where contains(description,'isabout(apple weight(.9),boy weight(.8),china weight(.7))') '权重
17、select * from table1 where freetext(column1,'char') '仅支持文字不支持表达式搜索
18、insert into table1 select column1,count(column1) from table2 group by column1 '统计
-----------------------------------------------------------------------------------------
1 说明:复制表(只复制结构,源表名:a 新表名:b)
SQL: select * into b from a where 1<>1
2 说明:拷贝表(拷贝数据,源表名:a 目标表名:b)
SQL: insert into b(a, b, c) select d,e,f from b;
3 说明:显示文章、提交人和最后回复时间
SQL: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
4 说明:外连接查询(表名1:a 表名2:b)
SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
5 说明:日程安排提前五分钟提醒
SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5
6 说明:两张关联表,删除主表中已经在副表中没有的信息
SQL:
delete from info where not exists ( select * from infobz where info.infid=infobz.infid )
7 说明:
从数据库中去一年的各单位电话费统计(电话费定额和电话费清单两个表来源)
SQL:
SELECT a.userper, a.tel, a.standfee, TO_CHAR(a.telfeedate, 'yyyy') AS telyear,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '01', a.factration)) AS JAN,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '02', a.factration)) AS FRI,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '03', a.factration)) AS MAR,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '04', a.factration)) AS APR,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '05', a.factration)) AS MAY,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '06', a.factration)) AS JUE,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '07', a.factration)) AS JUL,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '08', a.factration)) AS AGU,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '09', a.factration)) AS SEP,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '10', a.factration)) AS OCT,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '11', a.factration)) AS NOV,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '12', a.factration)) AS DEC
FROM (SELECT a.userper, a.tel, a.standfee, b.telfeedate, b.factration
FROM TELFEESTAND a, TELFEE b
WHERE a.tel = b.telfax) a
GROUP BY a.userper, a.tel, a.standfee, TO_CHAR(a.telfeedate, 'yyyy')
8 说明:四表联查问题:
SQL: select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....
9 说明:得到表中最小的未使用的ID号
SQL:
SELECT (CASE WHEN EXISTS(SELECT * FROM Handle b WHERE b.HandleID = 1) THEN MIN(HandleID) + 1 ELSE 1 END) as HandleID
FROM Handle
WHERE NOT HandleID IN (SELECT a.HandleID - 1 FROM Handle a)
10 说明:模糊查询,单字匹配(短横线代表待匹配内容)
select * from table where field1 like 'A_B_C'
11 说明:as的用法
select id,column1 * column2 as column from table1
as用法:
是给现有的字段名另指定一个别名的意思,比如:
select username as 用户名,password as 密码 from users
补充:比如其中的一个好处是:当字段名是英文或拼音缩写时,采用汉字替代之后可以给阅读带来方便
sql中as的用法和一些经典的sql语句
1、delete table1 from (select * from table2) as t2 where table1.id=t2.id
2、truncate table table1 (不在事务日志中做记录,比delete table快,但不能激活触发器)
3、update table1 set column=column+1 where id=(select id from table2)
4、update table1 set column=column+1 from table1,table2 where table1.id=table2.id
5、select top n [Percent] * from table1 '输出百分比记录
6、select id,column1 * column2 as column from table1 '可算明白as的用法了
7、select * from table1 where column1 like 'SQL#_G_O' escape '#' '单匹配
8、select table1.id from table1 where not exists (select table2.id from table2 where table1.id=table2.id) '这个应该比not in快一些
9、select table1.id from table1,table2 where table1.id<>table2.id '看复合查询机制
10、select table1.id from table1,table2,(select id from table3) as t3 where table1.id=table2.id and table2.id=t3.id '有些类似[1]了......
11、select * from table1 where column1 like '[A]%' or like '[^B]%'
12、select @column1=column1 from table1;select @column1 as column1 '存储到自定义变量
13、select * from table1 where contains(column1,'char1 or char2*') '全文索引
14、select * from table1 where contains(column1,'前有 near 中有 near 后有')
15、select * from table1 where contains(column1,'formsof(inflectional,go)') '派生
16、select * from table1 where contains(description,'isabout(apple weight(.9),boy weight(.8),china weight(.7))') '权重
17、select * from table1 where freetext(column1,'char') '仅支持文字不支持表达式搜索
18、insert into table1 select column1,count(column1) from table2 group by column1 '统计
-----------------------------------------------------------------------------------------
1 说明:复制表(只复制结构,源表名:a 新表名:b)
SQL: select * into b from a where 1<>1
2 说明:拷贝表(拷贝数据,源表名:a 目标表名:b)
SQL: insert into b(a, b, c) select d,e,f from b;
3 说明:显示文章、提交人和最后回复时间
SQL: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
4 说明:外连接查询(表名1:a 表名2:b)
SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
5 说明:日程安排提前五分钟提醒
SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5
6 说明:两张关联表,删除主表中已经在副表中没有的信息
SQL:
delete from info where not exists ( select * from infobz where info.infid=infobz.infid )
7 说明:
从数据库中去一年的各单位电话费统计(电话费定额和电话费清单两个表来源)
SQL:
SELECT a.userper, a.tel, a.standfee, TO_CHAR(a.telfeedate, 'yyyy') AS telyear,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '01', a.factration)) AS JAN,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '02', a.factration)) AS FRI,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '03', a.factration)) AS MAR,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '04', a.factration)) AS APR,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '05', a.factration)) AS MAY,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '06', a.factration)) AS JUE,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '07', a.factration)) AS JUL,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '08', a.factration)) AS AGU,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '09', a.factration)) AS SEP,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '10', a.factration)) AS OCT,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '11', a.factration)) AS NOV,
SUM(decode(TO_CHAR(a.telfeedate, 'mm'), '12', a.factration)) AS DEC
FROM (SELECT a.userper, a.tel, a.standfee, b.telfeedate, b.factration
FROM TELFEESTAND a, TELFEE b
WHERE a.tel = b.telfax) a
GROUP BY a.userper, a.tel, a.standfee, TO_CHAR(a.telfeedate, 'yyyy')
8 说明:四表联查问题:
SQL: select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....
9 说明:得到表中最小的未使用的ID号
SQL:
SELECT (CASE WHEN EXISTS(SELECT * FROM Handle b WHERE b.HandleID = 1) THEN MIN(HandleID) + 1 ELSE 1 END) as HandleID
FROM Handle
WHERE NOT HandleID IN (SELECT a.HandleID - 1 FROM Handle a)
10 说明:模糊查询,单字匹配(短横线代表待匹配内容)
select * from table where field1 like 'A_B_C'
11 说明:as的用法
select id,column1 * column2 as column from table1
参考资料: 蓝雷晶的新浪博客
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询