表1:
itemid --物品ID
itemprice --物品价格
buytime --购买时间表2:
itemid --物品ID
itemtype --物品种类现在要得到每个种类在一段时间内的销售比重比如对表2进行搜索select itmeid,itemtype from 表2 order by itemtype
得到结果如下:
itemid itemtype
4758 1
1157 1
1255 1
1256 1
3458 1
3460 1
3711 1
3737 1
3738 1
3949 1
3988 1
4310 1
4819 1
4230 1
4308 1
4480 1
4481 1
1154 1
1250 1
1047 1
1043 1
1003 1
1051 1
1153 1
1150 1
6416 2
3705 2
404 2
344 2
6417 2
4108 2
406 2
405 2
403 2
4106 2
402 2
383 2
401 2
5957 2
382 2
5524 2
6726 3
6625 3
6270 3
6825 3
6268 3
6269 3
6307 3
7026 3
7125 3
7825 3
7826 3
7925 3
7926 3
7025 3
6926 3
7126 3
6626 3
6725 3
6826 3
6925 3
10308 4
10309 4
4535 4
10306 4
4929 4
10307 4
4107 4
10310 4
4171 4
4172 4
4173 4
4174 4
4183 4
4185 4
4186 4
4187 4
4184 4
然后根据ID到表1中差找各种类销售比重下面的Sql不会写了,谁能指点我一下啊?
itemid --物品ID
itemprice --物品价格
buytime --购买时间表2:
itemid --物品ID
itemtype --物品种类现在要得到每个种类在一段时间内的销售比重比如对表2进行搜索select itmeid,itemtype from 表2 order by itemtype
得到结果如下:
itemid itemtype
4758 1
1157 1
1255 1
1256 1
3458 1
3460 1
3711 1
3737 1
3738 1
3949 1
3988 1
4310 1
4819 1
4230 1
4308 1
4480 1
4481 1
1154 1
1250 1
1047 1
1043 1
1003 1
1051 1
1153 1
1150 1
6416 2
3705 2
404 2
344 2
6417 2
4108 2
406 2
405 2
403 2
4106 2
402 2
383 2
401 2
5957 2
382 2
5524 2
6726 3
6625 3
6270 3
6825 3
6268 3
6269 3
6307 3
7026 3
7125 3
7825 3
7826 3
7925 3
7926 3
7025 3
6926 3
7126 3
6626 3
6725 3
6826 3
6925 3
10308 4
10309 4
4535 4
10306 4
4929 4
10307 4
4107 4
10310 4
4171 4
4172 4
4173 4
4174 4
4183 4
4185 4
4186 4
4187 4
4184 4
然后根据ID到表1中差找各种类销售比重下面的Sql不会写了,谁能指点我一下啊?
解决方案 »
- Navicat可以连接mysql,ecshop却不行
- mysql 存储过程的sql语句limit后面不能带变量
- 翻译 Twin Project
- mysql中,500万行记录,每隔100条抽一条记录,求一条高效sql,谢谢
- 一个性能难题,如何优化如下sql?
- 刚在win2000下装了PHP Home Edition 2,请教如何在MySQL创建数据库
- 使用MYSQL如何建立DNS
- 如何将mysql数据库转换到sql server 2000中。
- win7下源码安装mysql遇到了一堆问题,求高手指点
- 如何执行一次bat就往MySQL中插入一条数据记录执行bat的时间?
- mysql中奇怪的blob类型,高手请进
- MySQL版本选择问题。
from 表1 ,表2, (select Count(*) as CNT from 表1 where 表1.buytime between '2011-09-01' and '2011-10-01') c
where 表1.itemid=表2.itemid
And 表1.buytime between '2011-09-01' and '2011-10-01'
group by 表2.itemtype
type gold bizhong
1 3333 10%
2 2222 5%
....
from 表1 ,表2, (select Count(*) as CNT from 表1 where 表1.buytime between '2011-09-01' and '2011-10-01') c
where 表1.itemid=表2.itemid
And 表1.buytime between '2011-09-01' and '2011-10-01'
group by 表2.itemid,表2.itemtype
贴建表及插入记录的SQL,及要求结果出来看看
你的数据与要求结果不匹配?