Get Filtered Data From HubDB from Multiple Select Column - hubspot

I have a Table in HubDB as follows...
I have Filter data by Gender by Following Code Snippet
{% for row in hubdb_table_rows(675094, 'gender=1') %}
But, Now i want to filter Data by Multiple Filed. I'm stuck here.
I want data which has M5 value in Multiple Filed.

You can add multiple limits to your query with an &.
I haven't tested it but it should be something like:
{% for row in hubdb_table_rows(675094, 'gender=1&multiple_feed__contains=M5') %}

You can add multiple limits to your query with an &.
I haven't tested it but it should be something like:
{% for row in hubdb_table_rows(675094, 'gender=1&multiple_feed=M5') %}

Related

Create Multiple Tables in BigQuery Using dbt for-loop

I am trying to create individual tables inside a single dataset in BigQuery using a for-loop in dbt, going through a list of accounts, with no success so far.
A little bit of context - I am using Stitch to fetch data from Facebook Ads and to push it to our BigQuery warehouse. Then, based on the model below, create new separate table for each account with aggregated/modelled data.
The declaration of the variables looks like:
-- table that contains list of accounts
{% set account_data = ref('bq_acct_list') %}
{% set accounts = get_column_values(table=account_data, column='bq_name_suffix') %}
And the query that the tables have to created based on is:
SELECT
DATE_TRUNC(DATE(date_start), DAY) date,
account_id,
account_name,
ROUND(SUM(spend), 2) ad_spend
FROM `{{ target.project }}.{{account}}.ads_insights`
GROUP BY 1, 2, 3
What is missing (I think) is the wrapper of the query + the for-loop itself. Can anyone help me fill in the blanks?
dbt operates under a paradigm of one model (i.e. a .sql file in your models/ directory) is represented by one object (table/view) in your data warehouse — at the moment there's no way around that.
If you need to maintain separate tables per account I'd consider:
Wrapping up the logic into a macro:
-- macros/account_transform.sql
{% macro account_transform(account) %}
SELECT
DATE_TRUNC(DATE(date_start), DAY) date,
account_id,
account_name,
ROUND(SUM(spend), 2) ad_spend
FROM `{{ target.project }}.{{ account }}.ads_insights`
GROUP BY 1, 2, 3
{% endmacro %}
Create a separate model for each account, and call the macro in each model:
-- models/my_first_account.sql
{{ account_transform('my_first_account') }}
-- models/my_second_account.sql
{{ account_transform('my_second_account') }}
Depending on your exact use-case, you might also consider creating a master table for all accounts, by unioning them together. That way, you only have to create one model. Check out the article on "Unioning together identically-structured sources" for some techniques for this approach.

GCP Bigquery - query empty values from a record type value

I'm trying to query all resources that has empty records on a specific column but I'm unable to make it work. Here's the query that I'm using:
SELECT
service.description,
project.labels,
cost AS cost
FROM
`xxxxxx.xxxxx.xxxx.xxxx`
WHERE
service.description = 'BigQuery' ;
Here's the results:
As you can see, I'm getting everything with that query, but as mentioned, I'm looking to get resources with empty records only for example record 229,230 so on.
Worth to mention that schema for the column I'm trying to query is:
project.labels RECORD REPEATED
The above was mentioned because I tried using several combinations of WHERE but everything ends up in error.
To identify empty repeated record - you can use ARRAY_LENGTH in WHERE clause like in below example
WHERE ARRAY_LENGTH(project.labels) = 0

sql calculated column when find words

I am trying to accomplish the following.
There is a calculated field I need to create that sums the rows when it finds a specific word. Something like this:
SELECT sum(
case
when product.description like'%trans%'
or product.description like '%transitions%'
then sales
else null
end
) as transitions
How can I search for multiple words in a column using the conditional case to sum only the rows that have these words?
First, your particular example is poor because '%trans%' matches '%transitions%'. So, this is sufficient for your example:
SELECT sum(case when product.description like '%trans%'
then sales
end) as transitions
You can search for other things using or:
SELECT sum(case when product.description like '%trans%' or
product.description like '%cis%'
then sales
end) as transitions
Note that if you are looking for words in product.description then perhaps a text field is not the right structure (that is, perhaps you should be storing each word separately). Alternatively, you might want to look into full-text search.

How do I retrieve a specific order in Shopify Liquid?

The problem
I'm creating a proxy app page for a store in Shopify and would like to get a specific order based on the order id using liquid code.
The proxy page will have an url like this: /tools/integrator/order/{id} where {id} is the order id. The proxy page will create liquid code and a mix of other information from a custom database.
I would like to get the specific order with something like:
<p>
Created: customer.orders[xyz].created_at
</p>
where the xyz number is the order id, not the array index. The orders array doesn't seem to have an option to get an order by the order id but only by the index.
My current Non optimised solution
The only way I've found is to create a for loop and compare the id of each order with the id that I need to get:
{% for order in customer.orders %}
{% if order.id == 4225044174 %}
<p>Order found!</p>
{% endif %}
{% endfor %}
How can I get the order by order id without a loop?

Updating parts of a record in Access

Is there a way to update only parts of a database record? I have a table that lists a bunch of different items followed by their cost, but I would like to remove the cost from the item. For example:
Current table looks like this
---Item-------------
Apple- 1.35
Orange - 1.24
Grape - 2.00
ETC..
---------------------
I would like to update the table with the same records, but without the hyphened price at the end. There are hundreds of different records in this table, so I can't just update by a specific record. I've tried using wildcards, but I wasn't able to get the results I'm looking for. Is there a way of doing this?
If the part you want to remove always begins with a hyphen, and there won't be any hyphens as part of the item name then this code should do what you want:
update YourTable set item = left(item, instr(item,"-")-1)
Before you run the update you might want to try it as a select:
select left(item, instr(item,"-")-1) as newitem from YourTable
If your item name can contain hyphens maybe searching for a hyphen followed by a space would work: "- "
Also, a where clause should probably be used to avoid trying to update rows without the price part.
SELECT Left(item,InStr(item,"- ")-1) AS newitem
FROM YourTable
WHERE InStr(item,"- ") > 0;
I think I would go for Mid:
SELECT t.ExistingField,
Trim(Mid([existingfield],1,InStr([existingfield],"-")-1)) AS NewData
FROM Table t
So:
UPDATE Table
SET Table.UpdatedField = Trim(Mid([existingfield],1,InStr([existingfield],"-")-1))
WHERE Table.ExistingField Like "*-*"
Get the ParseWord function, stick it in a module, and reference it in your UPDATE query like so:
ParseWord([NameOfYourField], 1)
You can also use the Split() function to do the same thing.