日期:2014-05-16  浏览次数:20820 次

Mysql多表查询的一个问题
有这么几张表:
team表(商品信息表):
  id title price
--------------------
  1 XXXX 12
  2 xxx 20
  3 XXX 15 

team_click(商品点击量)表:
  click_id team_id click_count click_time click_ip
-------------------------------
  1 2 1 12312312 201.123.54.23
  2 3 2 ........ xxx.xxx.xxx.xxx
  3 1 8 ........ .
  4 1 1 ........ .

order(商品订单表):
 id team_id buy_count money
----------------------------------
 1 3 2 20
 2 1 1 12
 3 2 3 20 

现在要联合这些表 查询出:

商品ID 商品名 访客数 点击量 销售量
--------------------
 XXX XXX XXX XXX XXX

商品ID:(team表的ID)  
商品名:(team表的title)
访客数:(team_click表team_id=商品ID的个数)
点击量:(team_click表team_id=商品ID click_count的和) 
销售量:(order表team_id=商品ID buy_count的和)

请问各位大哥们 这个怎么写SQL啊?愁死我了

------解决方案--------------------
select A.id,A.title,sum(*),sum(B.click_count),sum(C.by_count)
from team A,team_click B ,order C
where A.id=B.team_id and A.id=C.team_id
group by A.id,A.title
------解决方案--------------------
(不要高估你的汉语表达能力或者我的汉语理解能力)
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
 
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
 
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。