-2

I am new to PostgreSQL and I don't know why my "as" statement is not working, below is the query:

with CTE as
(
SELECT *,rank() OVER(partition by Name ORDER BY AdministrationDate desc) AS rank_val
FROM ExamResult
)

select Name as 'Student Name', AdministrationDate as 'Admin date most recent',Score as 'Most Recent Score'
where rank_val=1 from CTE
UNION
select Name as 'Student Name', AdministrationDate as 'Admin date Prior attempt',Score as 'Prior Score'
where rank_val=2 from CTE

Is as not a part of Postgres

Swayam Shah
  • 200
  • 1
  • 12

1 Answers1

2

What you call “as” is called an “alias” in SQL.

It works fine, but note that aliases are identifiers, not string literals. As such, you have to use double quotes, not single quotes, to quote aliases that contain a non-standard character like a space.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263