私は2つのテーブルを持っています。
表 1 = ブランチ を含む
branch_id branch_name
表 2 = sales_data を含む
sales_id sales_date sales_branch sales_profit
各支店の 1 日の総売上高と 1 日の総利益を表示する必要はありません。特定の週の結果を戻す方法を知っているなど、データを戻す方法に本当に苦労しています。
また、すべてのブランチを常に表示し、何も販売していない場合は 0 を表示する必要があります。
どのように仕上げたいかの簡単な画像 ( http://i37.photobucket.com/albums/e71/dannyflap/screen_shot.jpg ) をまとめました。これは本当に私を夢中にさせています:(
アップデート
select sales_branch, WEEKDAY(sales_date), COUNT(sales_profit), SUM(sales_profit)
FROM sales_date
GROUP BY sales_branch, WEEKDAY(sales_date)
これにより、次の例が返されます。フィギュアは構成されています。
sales_branch, day, units, profit:
| branch1 | 0 (as day) | 16 | 439 |
| branch1 | 1 (as day) | 12 | 651 |
| branch1 | 2 (as day) | 22 | 312 |
| branch1 | 3 (as day) | 61 | 614 |
| branch1 | 4 (as day) | 12 | 541 |
| branch1 | 5 (as day) | 24 | 102 |
| branch1 | 6 (as day) | 21 | 145 |