我需要组合来自两个视图表的两个选择查询的结果,我正在从中执行计算。也许有一种更简单的方法可以使用 if...else 执行查询 - 任何指针?
本质上,我需要在 sql 查询 1 的条件下将所有内容除以 'ar.time_ratio',并忽略查询 2。
SELECT
gs.traffic_date,
gs.domain_group,
gs.clicks/ar.time_ratio as 'Scaled_clicks',
gs.visitors/ar.time_ratio as 'scaled_visitors',
gs.revenue/ar.time_ratio as 'scaled_revenue',
(gs.revenue/gs.clicks)/ar.time_ratio as 'scaled_average_cpc',
(gs.clicks)/(gs.visitors)/ar.time_ratio as 'scaled_ctr',
gs.average_rpm/ar.time_ratio as 'scaled_rpm',
(((gs.revenue)/(gs.visitors))/ar.time_ratio)*1000 as "Ecpm"
FROM
group_stats gs,
v_active_ratio ar
WHERE ar.group_id=gs.domain_group
和
SELECT
gs.traffic_date,
gs.domain_group,
gs.clicks,
gs.visitors,
gs.revenue,
(gs.revenue/gs.clicks) as 'average_cpc',
(gs.clicks)/(gs.visitors) as 'average_ctr',
gs.average_rpm,
((gs.revenue)/(gs.visitors))*1000 as "Ecpm"
FROM
group_stats gs,
v_active_ratio ar
where not ar.group_id=gs.domain_group