The SQL language is a bit like a toolkit for data. It consists of lots of little fiddly bits of syntax that, taken together, allow you to build complex edifices and return powerful results. For the uninitiated, the many tools can be quite confusing, and it's sometimes difficult to decide how to go about the process of building non-trivial queries, that is, queries that are more than a simple SELECT a, b FROM c;
A System for Building Queries
When you're building queries, you could use a system like the following:
- Decide which fields contain the values you want to use in our
output, and how you wish to alias those fields
- Values you want to see in your output
- Values you want to use in calculations . For example, to calculate margin on a product, you could calculate price - cost and give it the alias margin.
- Values you want …