sql - 按天求和和分组输出 SQL
问题描述
我无法通过别名 Gross_Demand 和 Units 引用。
,(CASE WHEN CONCAT(',',post_event_list,',') LIKE '%,1,%' THEN SPLIT(item, ";")[safe_offset(3)] END) Gross_Demand
,(CASE WHEN CONCAT(',',post_event_list,',') LIKE '%,1,%' THEN SPLIT(item, ";")[safe_offset(2)] END) Units
解决方案
故意不给你一个具体的答案,但我会像这样构造你的查询:
-- Declare your variables
DECLARE StartDate...
with hits as (
-- select what you need from your hits table, filter and unnest here
),
products as (
-- select and filter what you need from your products table here
),
joined as (
-- join the two sources together and do any additional filtering
select
date, visits, orders, gross_demand, units, etc...
from hits
join products
),
calcs as (
select
*,
gross_demand*units as revenue,
orders/visits * 100 as conversion_pct,
gross_demand*units/visits as revenue_per_visit
from joined
)
select * from calcs
将您的逻辑分解为步骤/块通常会使事情变得更容易。
推荐阅读
- ionic-framework - 如何在 Ionic 4 中导入自定义 css 和 js
- android - 无法在 AMD Ryzen 5 系统中运行模拟器?
- html - 将 Flex/CSS 与 wkhtmltopdf 一起使用
- javascript - yii2 ajax 验证表格
- c++ - 无论如何在不使用 windows.h 的情况下改变颜色
- imagemagick - image magick命令行使用上下文中冒号运算符是如何定义的
- mysql - 当您不能依赖 ID 按字面顺序排列时,如何批处理 SELECT 语句?
- c# - 如何使用 LINQ 遍历数组(或列表)中的所有元素?
- php - 如何遍历数组内的附加输入
- python - 硒有没有办法从最后一个光标位置移动到元素