Q:

Combine two queries into one without using temp tables

I want to substact mincall from callzero. I am getting mincall from the first query and callzero from the second. How can I combine these queries so I don't have to use temp tables?
select CONVERT(datetime, convert(varchar(10), min(CALENDAR))) as mincal 
from STATS
group by clientid

And :
select CONVERT(datetime, convert(varchar(10), min(CALENDAR))) as callzero, CLIENTID from STATS
where calls = 0
and CONVERT(datetime, convert(varchar(10), CALENDAR)) < getdate()-2
group by clientid

UPDATE
I have these queries merged as follows - 
select b.CLIENTID from
(
    select CONVERT(datetime, convert(varchar(10), min(CALENDAR))) as mincal
    from STATS
    group by CLIENTID
) a,
(
    select CONVERT(datetime, convert(varchar(10), min(CALENDAR))) as callzero, CLIENTID
    from STATS
    where calls = 0 and CONVERT(datetime, convert(varchar(10), CALENDAR)) < getdate()-2
    group by clientid
) b
group by clientid

But I still cannot subtract mincall from callzero without they being in the group by clause.
UPDATE 2
The calendar field is in this format yyyymmdd. For example, 20170922.

A:

I believe that your queries can be simplified in a single, simple statement by using conditional aggregation. 
Consider :
SELECT  
    clientid, 
    MIN(calendar) as mincal 
    MIN(CASE WHEN calls = 0 AND calendar < getdate()-2 THEN calendar END) as callzero,
    DATEDIFF(
        DAY,
        MIN(CASE WHEN calls = 0 AND calendar < getdate()-2 THEN calendar END),
        MIN(calendar)
    ) as date_interval 
FROM (
    SELECT 
        clientid, 
        CONVERT(datetime, convert(varchar(10), calendar)) calendar
    FROM STATS
)
GROUP BY clientid

Notes :

I understand that the dates in CALENDAR are stored as integers, hence the double conversion. To limit the number of conversions, I moved it to a subquery.
In the third column, only rows having calls = 0 and calendar within the last two days are taken into account ; for other rows, the CASE statement returns NULL, which is basically ignored by the MIN aggregate function.
in sql-server, DATE_DIFF can be used to substract dates (here, the query returns the number of days between the two computed dates)

