SQL: JOINS - AS Statement

AS Statement

The AS function allows us to rename columns or table selections with an alias.

Syntax:

-- AS 
SELECT column_1 AS column_title
FROM table_name;

Example: Rename the payment_id column to my_payment_column

-- Rename the payment_id column to my_payment_column
SELECT payment_id AS my_payment_column
FROM payment
limit 2;
##   my_payment_column
## 1             17503
## 2             17504

Example: Rename the SUM(AMOUNT) as total_spent

-- Rename the payment_id column to my_payment_column
SELECT customer_id, SUM(AMOUNT) AS total_spent
FROM payment
GROUP BY customer_id
limit 5;
##   customer_id total_spent
## 1           1      114.70
## 2           2      123.74
## 3           3      130.76
## 4           4       81.78
## 5           5      134.65