Skip to content

Instantly share code, notes, and snippets.

@oliviac12
Last active February 19, 2016 16:57
Show Gist options
  • Save oliviac12/23aa2127c7a02faf738a to your computer and use it in GitHub Desktop.
Save oliviac12/23aa2127c7a02faf738a to your computer and use it in GitHub Desktop.
Sql notes while studying SQL
#multiple condition using where VARIABLE in (Values), see example:
SELECT name, population FROM world
WHERE name in ('France', 'Germany' , 'Italy')
#if conditions includes more than one varibale, see example:
SELECT name, population, area FROM world
WHERE (area >3000000 and population < 250000000) or (area <3000000 and population > 250000000)
#if looking for partial value, use VARIABLE like "%", see example:
SELECT name FROM world
WHERE name like "United%"
#When you need to round a value to the near 10000, see example:
round(gdp/population, -3)
#convert timestamp to date and hour
extract(hour from TIMESTAMP 'epoch' + created_ts * interval '1 second') as hour,
date(TIMESTAMP 'epoch' + created_ts * interval '1 second') as date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment