1
私はこのようなテーブルを持っているを作るために:使用SELECT結果テーブル
私は、次のSELECT文を実行したい:最速のクエリは何
SELECT count(*) from table WHERE A=1 and date between 2013-02 and 2013-03
SELECT count(*) from table WHERE A=1 and date between 2013-03 and 2013-04
SELECT count(*) from table WHERE A=1 and date between 2013-04 and 2013-05
....
SELECT count(*) from table WHERE B=1 and date between 2013-02 and 2013-03
SELECT count(*) from table WHERE B=1 and date between 2013-03 and 2013-04
SELECT count(*) from table WHERE B=1 and date between 2013-04 and 2013-05
...etc
と私が持っていることができます結果は次のようなテーブルに並べ替えられます:
date |A=1 |B=1 |C=1 |...
2013-Feb|count|count|count|
2013-Mar|count|...
日付から月を抽出し、月でGROUP BYを実行します。最後に数えます。 –
これはピボットテーブルです。ソリューションの例については、http://stackoverflow.com/questions/7674786/mysql-pivot-tableを参照してください。 – hruske