Jump to content

Combined 2 select


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...