Use these queries to work with the Places data for business locations in the United States of America.
Use case 1: Return all restaurants in California
Query:
SELECT PLACEID, BUSINESSNAME, ADDRESS, CITY, STATE, ZIPCODE, LATITUDE, LONGITUDE, CATEGORY
FROM PLACES."places_usa"
WHERE STATE = 'CA'
AND CATEGORY = 'Restaurant';Output: Query returns all restaurant business details located in California.
Use case 2: Count of businesses by state
Query:
SELECT STATE, COUNT(*) AS BUSINESSCOUNT
FROM PLACES."places_usa"
GROUP BY STATE
ORDER BY BUSINESSCOUNT DESC;Output: Query returns the number of businesses grouped by state, sorted in descending order.
Use case 3: List all Starbucks locations in New York
Query:
SELECT BUSINESSNAME, ADDRESS, CITY, ZIPCODE, LATITUDE, LONGITUDE
FROM PLACES."places_usa"
WHERE STATE = 'NY'
AND BUSINESSNAME ILIKE '%Starbucks%';
``Output: Query returns all Starbucks locations in New York with address and coordinates.
Use case 4: Find all businesses within 5 miles of Times Square, NYC
Query:
SELECT PLACEID, BUSINESSNAME, ADDRESS, CITY, STATE, ZIPCODE, LATITUDE, LONGITUDE
FROM PLACES."places_usa"
WHERE ST_DistanceSphere(
ST_MakePoint(LONGITUDE, LATITUDE),
ST_MakePoint(-73.9855, 40.7580)
) <= 8046.72; -- 5 miles in metersOutput: Query returns all businesses located within 5 miles of Times Square, NYC.
Use case 5: Top 10 business categories in Texas
Query:
SELECT CATEGORY, COUNT(*) AS COUNT
FROM PLACES."places_usa"
WHERE STATE = 'TX'
GROUP BY CATEGORY
ORDER BY COUNT DESC
LIMIT 10;Output: Query returns the top 10 business categories in Texas based on count.
Use case 6: Identify all businesses that are part of a global chain
Query:
SELECT PLACEID, BUSINESSNAME, ADDRESS, CITY, STATE, ZIPCODE, GLOBALCHAINID
FROM PLACES."places_usa"
WHERE GLOBALCHAINID IS NOT NULL;
``Output: Query returns all businesses that belong to a global chain.
Use case 7: Find businesses without a chain affiliation
Query:
SELECT PLACEID, BUSINESSNAME, ADDRESS, CITY, STATE, ZIPCODE
FROM PLACES."places_usa"
WHERE CHAINID IS NULL
AND GLOBALCHAINID IS NULL;Output: Query returns businesses that are not affiliated with any chain.
Use case 8: Get all businesses located in US territories
Query:
SELECT PLACEID, BUSINESSNAME, ADDRESS, CITY, STATE, ZIPCODE
FROM PLACES."places_usa"
WHERE STATE IN ('AS', 'GU', 'MP', 'PR', 'VI', 'UM');
``Output: Query returns all businesses located in US territories such as American Samoa, Guam, Puerto Rico, etc.