Home > Mobile >  Result of division from two different tables
Result of division from two different tables

Time:11-05

I have query result from 1 table related with amount of done tickets in company. Second query is time spent on perform this tickets. Results comes from 2 not related tables.

Result 1 comes from:

    Count(DISTINCT case_id) AS a
    FROM   booker

Result 2 comes from:

SELECT sum(TO_NUMBER(LEFT(duration, 2),'99D999')   TO_NUMBER(SUBSTRING(duration, 3,3),'99D999') / 60   TO_NUMBER(RIGHT(duration, 2),'99D999') / 3600) 
FROM    time_ad 

Result 1 is number: 120

Result 2 is number: 12,234

I would like to have 1 query that extract results from both queries and devide it.

Any ideas to do it in 1 query?

Thank you in advance

CodePudding user response:

You can do it directly (not tested, but it should work):

SELECT 
(SELECT Count(DISTINCT case_id) AS a FROM booker) /
(SELECT sum(TO_NUMBER(LEFT(duration, 2),'99D999')   TO_NUMBER(SUBSTRING(duration, 3,3),'99D999') / 60   TO_NUMBER(RIGHT(duration, 2),'99D999') / 3600) 
FROM    time_ad) AS MyResult
  • Related