我希望将以下两个查询合并为一个:
select top 100 date, count(*) from sections
where content not like '%some condition%'
group by date
order by date;
select top 100 date, count(*) from sections
group by date
order by date;
就像这个问题,LEFT JOIN after GROUP BY? 除了我需要它适用于 MS SQL Server,而不是 MySQL(不同之处在于 MSSQL 不允许在 from 子句中使用子查询)。
我正在寻找一种方法让结果集包含三列,date
第一列count(*)
和第二列count(*)
。
我目前的解决方案是:
select top 100 date,
(select count(*) from sections s1
where content not like '%some condition%'
and s1.date = s2.date),
(select count(*) from sections s1
where s1.date=s2.date) from sections as s2
group by date
order by date;
有一个更好的方法吗?