# SQL

Snippets on basic & advanced functions
13 posts
SQL

### Use EXISTS to check if a row is present

Need to find if records from table A can also be found in table B? EXISTS is here to help.
SQL

### The SIGN function

Use SIGN to see if a number is positive, negative, or zero. It's as simple as it sounds. Apply SIGN(
SQL

### Use SAFE_DIVIDE to handle division by zero.

ππΌππ_πΏππππΏπ divides two numbers while handling the case where the denominator is zero. π Here's the syntax. ππ΄π»π΄π²π ππ°π΅π΄_π³πΈππΈπ³π΄(πππππππππ, πππππππππππ) π΅ππΎπΌ πππππππ If the denominator is zero
SQL

### CUBE+GROUP BY for Subtotals

We all have used GROUP BY, but do you know CUBE? For example, if I have a table of user
SQL

### Get subtotals with ROLLUP+GROUP BY

ππππππ generates extra rows that represent the subtotals. For exampleβ¦ To get the sum of spending of each user, you typically
SQL

### CROSS JOIN for all combinations

It is the cartesian products of both tables, if you're a math nerd. π Syntax: ππ΄π»π΄π²π * π΅ππΎπΌ πππππ_π· π²ππΎππ πΉπΎπΈπ½ πππππ_πΈ Note that there is no need
Great! Youβve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Travis Tang.