Excel to SQL cheat sheet

Every spreadsheet move on this site and the SQL that does the same job. Function names follow SQLite, which runs the lessons in your browser.

Excel to SQL cheat sheet: VLOOKUP, SUMIF, COUNTIF, pivot tables, IF, UNIQUE, LEFT and dates, with the SQL for each
The whole cheat sheet as one image, to save or print. Download · Save to Pinterest
In ExcelIn SQL
Look at a sheetSELECT * FROM tableLesson
Pick some columnsSELECT name, country FROM customersLesson
FilterWHERE country = 'Germany'Lesson
Sort A to Z / Z to AORDER BY col / ORDER BY col DESCLesson
Top 10 rowsLIMIT 10Lesson
=SUM / =COUNT / =AVERAGESUM(col) / COUNT(*) / AVG(col)Lesson
=MIN / =MAXMIN(col) / MAX(col)Lesson
Count unique valuesCOUNT(DISTINCT col)Lesson
=COUNTIF / =SUMIFWHERE … then COUNT(*) / SUM(col)Lesson
Several COUNTIFS side by sideSUM(CASE WHEN … THEN 1 ELSE 0 END)Lesson
Pivot tableGROUP BY colLesson
Pivot value filterHAVING SUM(col) > 100Lesson
=VLOOKUP / =XLOOKUPJOIN other ON other.id = t.other_idLesson
VLOOKUP keeping #N/A rowsLEFT JOINLesson
=IF / =IFSCASE WHEN … THEN … ELSE … ENDLesson
Remove Duplicates / =UNIQUESELECT DISTINCT colLesson
=LEFT / =MIDsubstr(text, start, length)Lesson
=LENlength(text)Lesson
=A2&" "&B2a || ' ' || bLesson
=SUBSTITUTEreplace(text, 'old', 'new')Lesson
=FINDinstr(text, 'x')Lesson
=TEXT(date,"yyyy-mm")strftime('%Y-%m', date)Lesson
=B2-A2 (days between)julianday(b) - julianday(a)Lesson
=EDATE(date, 1)date(d, '+1 month')Lesson
Moving average dragged downAVG(x) OVER (ORDER BY d ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)Lesson
Running totalSUM(x) OVER (ORDER BY d)Lesson
=RANK within a groupROW_NUMBER() OVER (PARTITION BY g ORDER BY x DESC)Lesson
A helper sheetWITH helper AS (SELECT …)Lesson