Difference between revisions of "Fraud Book"

From Bitnami MediaWiki
Jump to navigation Jump to search
 
(3 intermediate revisions by one other user not shown)
Line 10: Line 10:
 
p. 136
 
p. 136
  
 +
===The SQLizer===
 
<font face="Courier New" size="2">
 
<font face="Courier New" size="2">
 
<font color = "blue">WITH</font>&nbsp;<font color = "maroon">table_of_how_many_times_each_combination_of_zip_and_city_appeared</font>
 
<font color = "blue">WITH</font>&nbsp;<font color = "maroon">table_of_how_many_times_each_combination_of_zip_and_city_appeared</font>
Line 21: Line 22:
 
<br/><font color = "blue">ORDER</font>&nbsp;&nbsp;<font color = "blue">BY</font>&nbsp;<font color = "maroon">pctrank</font>&nbsp;<font color = "blue">ASC</font><font color = "silver">;</font>&nbsp;
 
<br/><font color = "blue">ORDER</font>&nbsp;&nbsp;<font color = "blue">BY</font>&nbsp;<font color = "maroon">pctrank</font>&nbsp;<font color = "blue">ASC</font><font color = "silver">;</font>&nbsp;
 
</font>
 
</font>
 +
 +
===Using wiki's built-in syntax highlighting===
 +
<syntaxhighlight lang='SQL'>
 +
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;
 +
</syntaxhighlight> 
 +
 +
 +
 +
<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>

Latest revision as of 03:26, 11 March 2022

Style Guides

p. 136

The SQLizer[edit]

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[edit]

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;


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;