Excel/SQL functions Flashcards
CAST
SQL: changes datatype (string to float)
CAST (revenue AS Float)
or
CAST (date AS date) AS date only
CONCAT (in excel/ databases)
CONCATENATE (in sheets)
SQL: joins 2 or more text strings
_____ (1,2) AS ___name it____ OR
Concatenate (A1, “:”, B1) if you want to add something
COALESCE
SQL: accounts for null values
SELECT
COALESCE (column1, column2, column3)
____ (1. 2, 3,0(backup if 1 isn’t available, try this field, then this field, then this field, then zero))
TRIM
SQL: to eliminate leading or trailing spaces
CASE
Change value/spelling of something (like Find/Replace)
SELECT
WHEN customer_name = “Johno” THEN “John”
ELSE customer_name
END AS updated_customer_name
OR
SELECT WHEN quantity >30 THEN 'above 30' WHEN quantity = 30 THEN 'Is 30' ELSE 'under 30' END AS QuantityText
SORT (sheets/excel syntax)
=SORT(range, sort column, is ascending (true or false))
ORDER BY
SELECT, FROM, ______column like Release_date DESC
SORT (databases/SQL)
ORDER BY
CONVERT (sheets)
Converts fareinheight to celcius
=CONVERT(B2, “F”, “C”)
SPLIT
=SPLIT (A2, “ “) (text, delimiter)(For ex: Ann Jones)
=TO_PURE_NUMBER(A2)
Converts to number without text ($ sign gone)
DATA VALIDATION
create checkboxes, lists to choose from
SAFE_CAST
how to make a date a string
SAFE_CAST (MyDate AS STRING) FROM MyTable
COUNT (3 types)
COUNT (column_name) - returns number of values in colum - doesn’t count nulls
COUNT(*) - counts the number of records in a table
COUNT (DISTINCT column_name) - returns number of distinct values of specified column
GROUP BY
I think all of them together = 1 entry
VALUE
converts string to number
COUNT DISTINCT
sql COUNT (DISTINCT column)
IF
IF (quantity>10, more, less)
IF (condition, value if true, value if false)
HAVING
Group by: Last Name HAVING COUNT (orders.orderID) > 10
COUNTIF
sheets
=COUNTIF(range, “value”)
=COUNTIF (B2-B50, “=1”)
SUMIF
=SUMIF (range, criteria, (sum_range))
=SUMIF (B2-B50, “=1”, C2-C50)
SUMIFS
=SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2,…])
=SUMIFS (B1:B9, A1:A9, “Fuel”, C1:C9, “12/15/2020”)
SUMPRODUCT
=SUMPRODUCT(array1, array2…)
= (multiplication of corresponding values, then adding them all together)
The value we’re calculating should NOT be equal to the value we specify
< > 4 < > 0 or ! = 0 ! = 4
EXTRACT
SQL - let’s us pull one part of a given date to use
EXTRACT (YEAR from starttime_run) AS Year
Returns the remainder of a division calculation
% Modulo operator
ROUND
sql
ROUND (number, # decimals)
ROUND(MAX(UnitPrice), 2)
WITH
sql
a type of temporary table that you can query from multiple times
WITH (new name) AS (select,from,where table)
Tells query t’s part of description and not part of the code
##
INNER,OUTER,LEFT, RIGHT JOIN
FROM _____table1_____
INNER JOIN ____table2____
ON table1.column1 = table2.column1
SELECT INTO
(temporary table) SELECT * INTO AfricaSales FROM GlobalSales WHERE Region=Africa
CREATE TABLE
CREATE TABLE AfricaSales AS ( SELECT* FROM GlobalSales WHERE Region= "Africa" )
IF
sql
SELECT
IF (genre=horror
, ‘will not watch’, ‘will watch’)
AS watch_category,
how to delete a table
DROP TABLE IF EXISTS table1
Create tables (2 ways)
CREATE TABLE IF NOT EXISTS CREATE OR REPLACE TABLE (tablename1) AS SELECT FROM WHERE
create temporary table
CREATE TEMP TABLE ExampleTable AS SELECT colors FROM favorite_colors