combining two select statements to return one result
Posted
by DalivDali
on Stack Overflow
See other posts from Stack Overflow
or by DalivDali
Published on 2010-05-07T18:48:57Z
Indexed on
2010/05/07
18:58 UTC
Read the original article
Hit count: 356
I need to combine the results for two select queries from two view tables, from which I am performing calculations. Perhaps there is an easier way to perform a query using if...else - any pointers?
Essentially I need to divide everything by 'ar.time_ratio' under the condition in sql query 1, and ignore that for query 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
and
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
© Stack Overflow or respective owner