Published by Patrick Mutisya · 14 days ago
Be able to produce different output layouts, including controlling the display of data, labels, and presenting results in tabular or columnar format.
In SQL the AS clause gives a column a user‑friendly label.
SELECT student_id AS "ID",
firstname || ' ' || lastname AS "Student Name",
grade AS "Result"
FROM students;
The result will show column headings ID, Student Name, and Result instead of the original field names.
Functions can change the appearance of data before it is displayed.
| Function | Purpose | Example | Result |
|---|---|---|---|
UPPER() | Convert text to uppercase | UPPER(city) | NEW YORK |
LOWER() | Convert text to lowercase | LOWER(Country) | england |
ROUND(number, d) | Round a numeric value to d decimal places | ROUND(salary, 2) | 4523.70 |
CONCAT(a, b, …) | Join several strings together | CONCAT(firstname, ' ', lastname) | Jane Doe |
Standard query results are displayed in a table where each row represents a record and each column a field.
SELECT productid, productname, price
FROM products
ORDER BY price DESC;
Typical screen output:
| product_id | product_name | price |
|---|---|---|
| 105 | Smartphone X | 799.99 |
| 112 | Laptop Pro | 1199.00 |
| 207 | Headphones | 149.95 |
When only a single field is required, a columnar (list) format can be used.
SELECT DISTINCT city
FROM customers
ORDER BY city;
Result displayed as a single column list:
Use concatenation to create a descriptive line for each record.
SELECT CONCAT('Order ', orderid, ': ', productname, ' (', quantity, ')') AS "Order Summary"
FROM orders;
Sample output:
GROUP BY with LabelsAggregated data often needs a clear label for each group.
SELECT department AS "Dept.",
COUNT(*) AS "No. of Staff",
A \cdot G(salary) AS "Avg Salary"
FROM staff
GROUP BY department;
Result example:
| Dept. | No. of Staff | Avg Salary |
|---|---|---|
| HR | 8 | 45,200 |
| IT | 12 | 58,750 |
| Sales | 15 | 39,400 |
AS to give columns meaningful headings.UPPER, ROUND, CONCAT) to control how data appears.