0

次の MySQL テーブルがあります。

TABLE: Products
----------------------
 id   |   productname
 1030 |   xBox 360
 1031 |   PlayStation 3
 1032 |   iPod Touche

TABLE: Sales
----------------------
 productid | saledate
 1031      | 2010-06-14 06:30:12
 1031      | 2010-06-14 08:54:38
 1030      | 2010-06-14 08:58:10
 1032      | 2010-06-14 10:12:47

今日販売した製品をphpを使用して取得し、販売番号と販売日ごとにグループ化します(可能な場合)、出力の例:

 Today's statistics:
 -Playstation 3 (2 sales)
 -Xbox 360 (1 sale)
 -iPod Touche (1 sale)

ありがとう

4

1 に答える 1

0

デビッド、

(テストされていない)の行に沿ったもの:

select 
p.productname,
count(s.productid)
from sales s inner join products p
on p.id=s.productid
where s.saledate=curdate()
group by p.productname

私が言ったように、テストされていませんが、あなたが求めていることをするように「感じます」..

ジム

于 2010-06-14T18:42:23.963 に答える