with tb as(
select *,1 a from book
union all
select *,2 from book_queue)
select convert(varchar,bookdate,23),sum(case when a=1 then 1 else 0 end),
SUM(case when a=2 then 1 else 0 end) from tb
group by convert(varchar,bookdate,23)写了一个,后面的接着写吧

解决方案 »

  1.   

    参考下把,两个表根据时间你在join一下
    select Ltrim(year(bookdate)) as 年 , count(*) as 预约数  from book group by year(bookdate)
    union all
    select Ltrim(year(bookdate))+'年' +Ltrim(month(bookdate))+'月' , count(*) as 预约数  from book group by Ltrim( year(bookdate))+'年' +Ltrim(month(bookdate))+'月'
    union all
    select Ltrim(year(bookdate))+'年' +Ltrim(datepart(quarter,bookdate))+'季度' , count(*) as 预约数  from book group by Ltrim(year(bookdate))+'年' +Ltrim(datepart(quarter,bookdate))+'季度'
      

  2.   

    select 
       isnull(a.bookdate,b.bookdate) as bookdate,a.预约数,b.排队数
    from
      (select bookdate,count(1) as 预约数 from book group by bokdate) as a
    full join
       (select bookdate,count(1) as 排队数 from book_queue group by bokdate) as b
    on 
       a.bookdate=b.bookdate
    union all
    ...