47. Math Expressions
Beginner Mode
Scenario
You have a table of user-submitted text entries that may or may not represent valid mathematical expressions.
Task
Write a Snowflake SQL query that:
- Selects all columns from
{{ ref("expressions") }} - Filters to only include rows where the
expressioncolumn is a valid math expression (contains only digits and the operators+,-,*,/, with at least one operator separating digit groups)
Schema
expressions
| Column | Type | Description |
|---|---|---|
| id | Integer | Unique identifier for each entry |
| expression | String | User-submitted text that may be a math expression |
Example
expressions:
| id | expression |
|---|---|
| 1 | 8+2 |
| 2 | hello |
| 3 | 9/3 |
| 4 | test123 |
| 5 | 4*7-1 |
Expected Output:
| id | expression |
|---|---|
| 1 | 8+2 |
| 3 | 9/3 |
| 5 | 4*7-1 |
Note: Only rows containing digits separated by arithmetic operators (
+,-,*,/) are kept. Rows with alphabetic characters or other non-matching patterns are excluded.
Code Environment
Sign in or try as guest to run your code.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
IBM
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla