mysql中 ,如何用 as 取别名 谢谢大家!!!

mysql中 ,如何用 as 取别名 谢谢大家!!!,第1张

比如:

1、selec name as “姓名” ,sex as "性别" from user

2、select uname as “姓名”,oname as "英文名" ,usex as "性别" from user u ,other o where uid = oid;

as不是给表里的字段取别名,而是给查询的结果字段取别名。

其目的是让查询的结果展现更符合人们观看习惯,在多张表查询的时候可以直接的区别多张表的同名的字段。

扩展资料:

SQL别名:

SQL别名用于为表或表中的列 提供临时名称。

SQL别名通常用于使表名或列名更具可读性。

SQL一个别名只存在于查询期间。

别名使用AS关键字赋予。

在下列情况下使用别名:

1,查询涉及多个表

2,用于查询函数

3,需要把两个或更多的列放在一起

4,列名长或可读性差

语法

1、表名的别名语法

SELECT 列名

FROM 表名 AS 别名;

2、列名的别名语法:

SELECT 列名 AS 别名

FROM 表名

3、表名和列名的别名混合使用语法:

SELECT 列名 AS 别名

FROM 表名 AS 别名

语法举例

1、使用表名称别名

有两个表分别是:"Persons" 和 "Product_Orders"。分别为它们指定别名 "p" 和 "po"。列出 "John Adams" 的所有定单。

SELECT poOrderID, pLastName, pFirstName

FROM Persons AS p, Product_Orders AS po

WHERE pLastName='Adams' AND pFirstName='John';

2、使用列名称别名

查询 Persons 表中的 LastName 列 (为其定义别名 '姓氏')和 FirstName 列(为其定义别名 ‘名字’),输出所有结果值。

SELECT LastName AS 姓氏, FirstName AS 名字

FROM Persons

你好,刚翻了书,查下SQL语句除了有中文的句子,别的没看到有用句号的。一般的都用的是逗号,而且要特别注意,这个逗号是在输入法在英文状态下输入的,否则在开发工具中SQL语句你是无法调试成功的。

as用法:

是给现有的字段名另指定一个别名的意思,比如:

select username as 用户名,password as 密码 from users

补充:比如其中的一个好处是:当字段名是英文或拼音缩写时,采用汉字替代之后可以给阅读带来方便

sql中as的用法和一些经典的sql语句

1、delete table1 from (select from table2) as t2 where table1id=t2id

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 table1id=table2id

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 table1id from table1 where not exists (select table2id from table2 where table1id=table2id) '这个应该比not in快一些

9、select table1id from table1,table2 where table1id<>table2id '看复合查询机制

10、select table1id from table1,table2,(select id from table3) as t3 where table1id=table2id and table2id=t3id '有些类似[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 atitle,ausername,badddate from table a,(select max(adddate) adddate from table where tabletitle=atitle) b

4 说明:外连接查询(表名1:a 表名2:b)

SQL: select aa, ab, ac, bc, bd, bf from a LEFT OUT JOIN b ON aa = bc

5 说明:日程安排提前五分钟提醒

SQL: select from 日程安排 where datediff('minute',f开始时间,getdate())>5

6 说明:两张关联表,删除主表中已经在副表中没有的信息

SQL:

delete from info where not exists ( select from infobz where infoinfid=infobzinfid )

7 说明:

从数据库中去一年的各单位电话费统计(电话费定额和电话费清单两个表来源)

SQL:

SELECT auserper, atel, astandfee, TO_CHAR(atelfeedate, 'yyyy') AS telyear,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '01', afactration)) AS JAN,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '02', afactration)) AS FRI,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '03', afactration)) AS MAR,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '04', afactration)) AS APR,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '05', afactration)) AS MAY,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '06', afactration)) AS JUE,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '07', afactration)) AS JUL,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '08', afactration)) AS AGU,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '09', afactration)) AS SEP,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '10', afactration)) AS OCT,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '11', afactration)) AS NOV,

SUM(decode(TO_CHAR(atelfeedate, 'mm'), '12', afactration)) AS DEC

FROM (SELECT auserper, atel, astandfee, btelfeedate, bfactration

FROM TELFEESTAND a, TELFEE b

WHERE atel = btelfax) a

GROUP BY auserper, atel, astandfee, TO_CHAR(atelfeedate, 'yyyy')

8 说明:四表联查问题:

SQL: select from a left inner join b on aa=bb right inner join c on aa=cc inner join d on aa=dd where

9 说明:得到表中最小的未使用的ID号

SQL:

SELECT (CASE WHEN EXISTS(SELECT FROM Handle b WHERE bHandleID = 1) THEN MIN(HandleID) + 1 ELSE 1 END) as HandleID

FROM Handle

WHERE NOT HandleID IN (SELECT aHandleID - 1 FROM Handle a)

10 说明:模糊查询,单字匹配(短横线代表待匹配内容)

select from table where field1 like 'A_B_C'

11 说明:as的用法

select id,column1 column2 as column from table1

这是sql server的一个规则所决定的

sql server中派生表是不能单独作为表名的  一定要给它个别名当做表名

这里你的派生表就是 (select Classification from NewsInfo) 如果不加 as a 就不能直接用在 from后面。

SQL Server 是Microsoft 公司推出的关系型数据库管理系统。

具有使用方便可伸缩性好与相关软件集成程度高等优点,可跨越从运行Microsoft Windows 98 的膝上型电脑到运行Microsoft Windows 2012 的大型多处理器的服务器等多种平台使用。

Microsoft SQL Server 是一个全面的数据库平台,使用集成的商业智能 (BI)工具提供了企业级的数据管理。

Microsoft SQL Server 数据库引擎为关系型数据和结构化数据提供了更安全可靠的存储功能,使您可以构建和管理用于业务的高可用和高性能的数据应用程序。

select a from

(slect ,(abs(aaa-"&rs("aaa")&")+(abs(bbb-"&rs("bbb")&")) as distance from table) a

order by adistance asc

以上就是关于mysql中 ,如何用 as 取别名 谢谢大家!!!全部的内容,包括:mysql中 ,如何用 as 取别名 谢谢大家!!!、计算机二级VF里,SQL语言输入的时候,什么时候用逗号,什么时候用句号怎么区分as怎么用啊、sqlserver中的as是什么意思等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9289931.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存