sam123
sam123

Reputation: 119

Issue with Table_Date_Range function

I am trying to figure out what is wrong with my below query, when i run it, it seems to ask me to add a group by to a record that is not in my statement.

SELECT date, 
SUM(totals.visits) as visits,
SUM(totals.transactions) as Transactions,
SUM( totals.transactionRevenue) as Revenue,
SUM (hits.eCommerceAction.action_type ='3'),
Sites
FROM 
(SELECT *, "SiteA" as Sites
FROM (TABLE_DATE_RANGE([mydata.ga_sessions_],DATE_ADD(CURRENT_TIMESTAMP(), -6, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'))), 
(TABLE_DATE_RANGE([mydata.ga_sessions_intraday_], DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'), CURRENT_TIMESTAMP()))
GROUP BY
date
ORDER BY
date DESC);

please let me know thanks

Upvotes: 0

Views: 51

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172993

I think you wrongly positioned your group by and order by.
Assuming that the rest of code make sense - Below should work

SELECT 
  date, 
  SUM(totals.visits) AS visits,
  SUM(totals.transactions) AS Transactions,
  SUM( totals.transactionRevenue) AS Revenue,
  SUM (hits.eCommerceAction.action_type ='3'),
  Sites
FROM (
  SELECT *, "SiteA" AS Sites
  FROM 
  (TABLE_DATE_RANGE([mydata.ga_sessions_],DATE_ADD(CURRENT_TIMESTAMP(), -6, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'))), 
  (TABLE_DATE_RANGE([mydata.ga_sessions_intraday_], DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'), CURRENT_TIMESTAMP()))
)
GROUP BY date, Sites
ORDER BY date DESC

Upvotes: 1

Related Questions