Sunday, September 7, 2014

Functions

RIGHT/LEFT

//start at the right side of location and get 2 characters
SELECT RIGHT(location, 2) FROM my_contacts

SELECT LEFT(location, 2) FROM my_contacts

SUBSTRING_INDEX

SELECT SUBSTRING_INDEX(location, ',', 1) FROM my_contacts
Finds everything in front of a specific character or string
If 1 were to be 2, then the second occurrence of the , would be looked and everything until that would be returned

SUM

SELECT SUM(sales)
FROM cookie_sales
WHERE first_name = 'Keith';

No comments:

Post a Comment