Jump to content

Combined 2 select


NewEra13

Recommended Posts

Hello i have these 2 metrics that works good so far:

-- --------------------------------------------
-- Nb Unique Accounts 
-- -------------------------------------------
select count(distinct(O.user_id))
from DB.order O LEFT JOIN DB.orderCompleted OrC
    ON O.id  = OrC.order_id
where reason in ('2') 

 

-- --------------------------------------------
-- Nb Accounts that are eighter deactivated or invalid
-- -------------------------------------------
select count(distinct(O.user_id))
from DB.order O JOIN DB.orderCompleted OrC
    ON O.id  = OrC.order_id
where reason (0,1) 

 

QUESTION#1: We now need a 3 rd metric that will caclculate the % of nb of accounts that are eighter deactivated or invalid. How could we acheive that ?

QUESTION#2: We would also like to only have 1 big SQL performing all 3 small queries above in order to then use this unioned or joined big sql into a Business Intelligence Reporting Tool that allows to use sql coding in order to display it in a crossTab 

 

Thanks to all !

Link to comment
Share on other sites

You can use a select query as one of the fields to select, so you can have a select query that selects each of those values from the queries above, and does division to get the percentage.  That's also how you would run all of them at once.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...