0

いくつかのテーブルが与えられた場合、where 句が含まれているテーブルの行数をポーリングする最良の方法は何ですか? 行数の毎日の記録を含むテーブルに挿入できるように、一度に実行したいと思います。

tableA - 条件 1 に適合するすべての行の数、特定の列値 X select count(*) from tableA where col1 = X

tableA - 条件 2 に適合するすべての行の数、特定の列値 Y select count(*) from tableA where col2 = Y

これら 2 つは次のように簡単に組み合わせることができます。

select
(select count(*) from tableA where col1 = X) as 'X count',
(select count(*) from tableA where col2 = Y) as 'Y count'

しかし今、私は追加したいと思います: tableB - 最後に指定された間隔内に作成されたすべての行の数

select count(*) from tableB where dateCreated >= date_sub(curdate(), interval 1 day) where col3 = Z;

これは私に与えます:

select
(select count(*) from tableA where col1 = X) as 'X count',
(select count(*) from tableA where col2 = Y) as 'Y count',
(select count(*) from tableB where dateCreated >= date_sub(curdate(), interval 1 day)) as 'Z count';

ただし、実行が非常に遅いようですが、この場合、行をカウントするより効率的な方法はありますか?

4

1 に答える 1