| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:大家都做做
只看楼主 加入收藏
jimn2000
Rank: 2
等 级:新手上路
威 望:3
帖 子:274
专家分:0
注 册:2006-4-3
收藏
 问题点数:0 回复次数:7 
大家都做做

有个表price中数据如下:
sp_id price1 line_id
101 1.0 1
102 1.3 2
101 1.5 3
102 2.0 4
101 1.6 5
102 1.1 6
。。。
如何实现以下查询结果?
sp_id price1 price2 price3 price4 price5 price6 最低price 最高price 平均pirce
101 1.0 1.5 1.6 。 。 。
102 1.3 2.0 1.1 。 。 。

按line_id的升序排列,取前
六个price,取平均。。

搜索更多相关主题的帖子: 101 102 price 如何 
2006-06-26 16:37
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 
line_id 不是按 sp_id分组的?

2006-06-26 16:43
jimn2000
Rank: 2
等 级:新手上路
威 望:3
帖 子:274
专家分:0
注 册:2006-4-3
收藏
得分:0 
恩,不是的。

欢迎大家访问我的网站 www. 域名代理网站 web.
2006-06-26 16:48
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 

换句话说,就6行数据

手动处理下的了,写SQL麻烦死了


2006-06-26 16:50
jimn2000
Rank: 2
等 级:新手上路
威 望:3
帖 子:274
专家分:0
注 册:2006-4-3
收藏
得分:0 
呵呵。不是拉。那如果很多行的话也是有可能的拉。
想要用sql语句实现啊

欢迎大家访问我的网站 www. 域名代理网站 web.
2006-06-26 16:58
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 
反正你只取前6个line_id,数据在多也一样


2006-06-26 17:01
jiweida
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-4-9
收藏
得分:0 

就取三个价吧

select top 3 identity(int,1,1) as xh,sp_id,price1,line_id into #a from price where sp_id='101'order by sp_id,line_id
select top 3 identity(int,1,1) as xh,sp_id,price1,line_id into #b from price where sp_id='102'order by sp_id,line_id

select sp_id,(select price1 from #a where xh=1)as price1,
(select price1 from #a where xh=2)as price2,(select price1 from #a where xh=3)as price3,
min(price1)as 最低价,max(price1)as 最高价,avg(price1)as 平均价 from #a where sp_id='101'
group by sp_id
union
select sp_id,(select price1 from #b where xh=1)as price1,
(select price1 from #b where xh=2)as price2,(select price1 from #b where xh=3)as price3,
min(price1)as 最低价,max(price1)as 最高价,avg(price1)as 平均价 from #b where sp_id='102'
group by sp_id

drop table #a
drop table #b


真便宜呀真便宜真便宜呀真便宜。。。。。。。
2006-06-26 17:14
jimn2000
Rank: 2
等 级:新手上路
威 望:3
帖 子:274
专家分:0
注 册:2006-4-3
收藏
得分:0 
如果有2个表。行数都是5行。怎么样组合成一个大表。也是5行,就是列数是2个表的总和。
比如说:一个表是
id code
1 34
2 54
3 56
4 66
5 67

另一个表是
td shumu
6 34
7 54
8 56
9 66
10 67


现在要组成大表是这样的

id code td shumu
1 34 6 34
2 54 7 54
3 56 8 56
4 66 9 66
5 67 10 67

怎么实现啊






欢迎大家访问我的网站 www. 域名代理网站 web.
2006-06-26 18:50
快速回复:大家都做做
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014163 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved