If your table A is not with 1 row, you will have cartesian query (isn't there a join of A and B?).
You can speed up the query with index on B.date (if you are selecting small % of all rows in B) and large SORT_AREA_SIZE for the group by.