0
user table
========
id(int) | name(varchar)
------------------------
1 | user1
2 | some_other_user
product table
===============
id(int) | user_id(int) | product(varchar) | status(varchar)
------------------------------------------------------------
1 | 1 | product1 | bought
2 | 1 | product3 | sold
3 | 2 | product22 | sold
4 | 2 | product2 | bought
5 | 2 | product4 | sold
6 | 1 | product5 | bought
7 | 1 | product7 | sold
我需要获取用户的姓名,他有多少产品,多少这些产品都这样做有一个status = sold
,用一个单一的MySQL查询。有任何想法吗?我怎么能在一个MySQL查询
'status'应该是标准化的:你是在浪费分贝的空间,你很容易犯错误... – Marco 2012-04-10 11:40:17