0

Problem

I'm creating a query to uniformly distribute Facebook ad spend amount per ad id's.

Syntax stopped me.

SELECT 
t.lead_city, 
t.lead_time,
t.facebook_ad_id,
t.facebook_leadads_id,
t.id_promo,
t.value,
(d.spent / CAST((SELECT COUNT(*) as cnt FROM `unified.FF_FACEBOOKLEADADS_DISCOUNTS_VISITS` t2 where t.facebook_ad_id = t2.facebook_ad_id) AS decimal(10,2))) as DistributedSpend
FROM `unified.FF_FACEBOOKLEADADS_DISCOUNTS_VISITS` t
INNER JOIN `unified.ads_data` d
ON d.ad_id = t.facebook_ad_id

This gives an error of "Expected ")" but got "(" at [24:178]". Can anyone direct to a BigQuery syntax resource or point out the mistake I'm making?

1
  • You should provide sample data, desired results, and an explanation of what you are trying to do. Commented Jun 18, 2018 at 17:02

1 Answer 1

3

DECIMAL(10,2) is not a valid BigQuery datatype. Try using NUMERIC data type instead.

https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.