(sql plus)如何别名列

时间:2018-04-29 21:17:17

标签: sqlplus

我一直在尝试使用别名来更改列名

我有三个表:姓名,成员和付款

我从互联网上采用了两种不同的语法,我尝试了两种语法

第一个:

SELECT n.firstname AS [First Name], n.lastname AS [Last Name], m.username AS UserName,
       m.birthday AS Birthday, m.email AS Email, m.phone_no AS Phone, 
       p.MembershipType AS [Membership Type]
FROM member AS m, name AS n, payment AS p
WHERE (m.username = n.username) and (m.username = p.username)
ORDER by n.firstname;
第二个:

SELECT n.firstname 'First Name', n.lastname 'Last Name', m.username 
       'UserName', m.birthday 'Birthday',
        m.email 'Email', m.phone_no 'Phone', p.MembershipType 'Membership Type'
FROM member m, name n, payment p
WHERE (m.username = n.username) and (m.username = p.username)
ORDER by n.firstname;

但它显示" FROM关键字未找到预期的位置" 我做错了什么?

1 个答案:

答案 0 :(得分:0)

我假设您使用的是 Oracle 数据库。

如果alias_name包含空格,则必须将alias_name括在引号

因此您的查询可能如下所示:

SELECT n.firstname "First Name", n.lastname "Last Name", m.username 
       "UserName", m.birthday "Birthday",
        m.email "Email", m.phone_no "Phone", p.MembershipType "Membership Type"
FROM member m, name n, payment p
WHERE (m.username = n.username) and (m.username = p.username)
ORDER by n.firstname;