Difference between revisions of "Fraud Book"
Jump to navigation
Jump to search
| Line 21: | Line 21: | ||
<br/><font color = "blue">ORDER</font> <font color = "blue">BY</font> <font color = "maroon">pctrank</font> <font color = "blue">ASC</font><font color = "silver">;</font> | <br/><font color = "blue">ORDER</font> <font color = "blue">BY</font> <font color = "maroon">pctrank</font> <font color = "blue">ASC</font><font color = "silver">;</font> | ||
</font> | </font> | ||
| + | |||
| + | * Using wiki's built-in syntax highlighting | ||
| + | <syntaxhighlight lang='SQL'>SELECT c.fname, c.lname, a.address | ||
| + | FROM customer c, address a | ||
| + | WHERE c.address_id = a.address_id | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang='SQL'> | ||
| + | SELECT | ||
| + | Product, AVG(price), MIN(price), MAX(price), | ||
| + | MAX(price) - MIN(price) AS price_change | ||
| + | FROM store_prices_log | ||
| + | WHERE DayID BETWEEN {min_day} AND {max_day} | ||
| + | GROUP BY 1 | ||
| + | ORDER BY price_change DESC; | ||
| + | </syntaxhighlight> | ||
Revision as of 21:05, 10 March 2022
- Style Guides
- SQL Style Guide
- GitLab guide
- Mozilla (Firefox) documentation
- learnsql.com
- AWS SQL standard
- "Modern" SQL from github
- The Holy Grail (SQL formatter)
p. 136
WITH table_of_how_many_times_each_combination_of_zip_and_city_appeared
AS (SELECT zipcode,city,Count(*) AS count_orders
FROM shipping_addresses
GROUP BY 1,2)
SELECT city,Percent_rank()
OVER (
partition BY zipcode
ORDER BY count_orders) AS PctRank
ORDER BY pctrank ASC;
- Using wiki's built-in syntax highlighting
SELECT c.fname, c.lname, a.address
FROM customer c, address a
WHERE c.address_id = a.address_id
SELECT
Product, AVG(price), MIN(price), MAX(price),
MAX(price) - MIN(price) AS price_change
FROM store_prices_log
WHERE DayID BETWEEN {min_day} AND {max_day}
GROUP BY 1
ORDER BY price_change DESC;