ETL SQL Statement
Hi,
I'm not familiar with SQL and wondering if someone can help with a SQL statement in an ETL that would solve the below(hope it makes sense)...
COLUMN1(txt) | COLUMN2(date) | COLUMN3(date) |
datapoint1 | oct 18 2020 | if 'column1' = 'datapoint1' then 'column2' minus 1 mth from the datafield in Col2' |
datapoint2 | oct 18 2020 | if 'column1' = 'datapoint2' then 'column2' minus 2 mths from the datafield in Col2' |
result...
COLUMN1(txt) | COLUMN2(date) | COLUMN3(date) |
datapoint1 | oct 18 2020 | Sept 2020 |
datapoint2 | oct 18 2020 | August 2020 |
Best Answer
-
If you are using MySQL, you could do this:
SELECT Column1, Column2, CASE WHEN column1 = 'datapoint1' THEN DATE_SUB(column2, INTERVAL 1 MONTH) WHEN column1 = 'datapoint2' THEN DATE_SUB(column2, INTERVAL 2 MONTH) END as Column3 FROM MyTable
You can also do this in MagicETL, which might be worth doing if you are not comfortable with SQL. You would use the Filter tile to split your data into two groups: datapoint1 and datapoint2. You would then use the Date Operations tile on both of those and use the subtract from date function in the tile and subtract 1 month for datapoint1 and 2 months for datapoint2. You would then use the Append tile to bring the datasets back together.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1
Answers
-
If you are using MySQL, you could do this:
SELECT Column1, Column2, CASE WHEN column1 = 'datapoint1' THEN DATE_SUB(column2, INTERVAL 1 MONTH) WHEN column1 = 'datapoint2' THEN DATE_SUB(column2, INTERVAL 2 MONTH) END as Column3 FROM MyTable
You can also do this in MagicETL, which might be worth doing if you are not comfortable with SQL. You would use the Filter tile to split your data into two groups: datapoint1 and datapoint2. You would then use the Date Operations tile on both of those and use the subtract from date function in the tile and subtract 1 month for datapoint1 and 2 months for datapoint2. You would then use the Append tile to bring the datasets back together.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
Thanks Mark, it worked! One thing - instead of a filter tile I used Group By and added the sql statement mentioned above in the Formula box. Thanks again!
0 -
... i don't know your data, but i'm not sure why you'd do it in a GROUP BY instead of a FORMULA tile.
Also, instead of managing crazy math with a CASE statement, create an Interval column that says how many months to go back (i.e. 1 or 2) and then use your Formula (or GROUP BY) tile to pass the interval (number of months) as a variable.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
Hello @nj-John-mirc ,
I'm happy to let you know we have just released Code Block apps in our Domo Appstore. These allow customers and Domo experts such as yourself, to publish code blocks like the ones you've created for distribution in the Appstore. The publish process for the code blocks is currently in an early beta. The supported code blocks are:
- Beast Mode- SQL
- R
- Python
- Jupyter Notebook
If you are interested in publishing your code blocks, let me know and we can enable it for you.Cheers,
Cody SmithDirector of Product, Domo
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive