Mahesh
Mahesh

Reputation: 1333

Compute % results of two SQL queries

I have two sql queries below. each query returns an integer. Please help me in writing a new sql query which computes (query1-query2)*100/query1

Upvotes: 1

Views: 57

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270463

One method is:

with q1 as (
      <query 1 here>
     ),
     q2 as (
      <query 2 here>
     )
select (q1.cw_va_df - q2.cw_va_df) * 100.0 / q1.cw_va_df
from q1 cross join q2

Upvotes: 6

Related Questions