Skip to content

Instantly share code, notes, and snippets.

@ivankatliarchuk
Created August 4, 2015 20:11
Show Gist options
  • Save ivankatliarchuk/46c3813a0324346a3e5c to your computer and use it in GitHub Desktop.
Save ivankatliarchuk/46c3813a0324346a3e5c to your computer and use it in GitHub Desktop.
left outer join
SELECT product.model, count(pc.model) FROM product
LEFT OUTER JOIN pc
ON product.model = pc.model
GROUP BY product.model;
SELECT model FROM product
WHERE model NOT IN (
SELECT model FROM pc);
SELECT DISTINCT model FROM pc;
SELECT to_char(date, 'yyyy') as year,
CASE
WHEN count(*) IS NULL
THEN 0
ELSE count(*)
END
FROM battles
GROUP BY 1
ORDER BY 1 DESC;
SELECT to_char(date, 'yyyy') as year
FROM battles
ORDER BY 1 DESC;
SELECT date FROM battles;
SELECT * FROM daterange('01','05');
SELECT day::date
FROM generate_series('2010-01-20', '2010-01-24', INTERVAL '1 day') day;
SELECT DATEADD(d, N, '0001-01-22')
FROM Numbers -- A table containing the numbers 0 through N
WHERE N <= 5;
select trunc(sysdate-dayincrement, 'DD')
from dual, (select level as dayincrement
from dual connect by level <= 30);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment