主题:查询怎样实现表内每一个日期的金额从大到小排列的前10名,请高手帮忙。
			 shandong
				 [专家分:0]  发布于 2009-12-05 20:23:00
 shandong
				 [专家分:0]  发布于 2009-12-05 20:23:00							
			原表一内数据排列如下
产品    金额    日期
台灯    65       8.29
优盘    55       8.25
茶杯    50       9.2
文具    45       8.29
鼠标    40       8.25
托盘    35       9.2
通过查询[b]SELECT * FROM 表一 ORDER BY 日期 desc,金额 desc    [/b]得到了如下效果
产品    金额    日期
茶杯    50      9.2
托盘    35      9.2
台灯    65      8.29
文具    45      8.29
优盘    55      8.25
鼠标    40      8.25
我想按照每一个日期的金额都按照从大到小的排列,同时只显示金额从大到小的前10位或者前几位,我不知道该怎么做,,请各位帮忙
						
					 
		
			
回复列表 (共4个回复)
		
								
				沙发
				
					 cbl518 [专家分:57140]  发布于 2009-12-06 10:48:00
cbl518 [专家分:57140]  发布于 2009-12-06 10:48:00				
				用 UNION 连接多个子查询,
要每个时间段不同的子查询,前十个记录。
							 
						
				板凳
				
					 shandong [专家分:0]  发布于 2009-12-06 12:00:00
shandong [专家分:0]  发布于 2009-12-06 12:00:00				
				
非常感谢cbl518大师的帮助,但小弟还是不知道怎样来写,麻烦cbl518大师给写一下,[em1]
							 
						
				3 楼
				
					 wuzhouhong [专家分:10890]  发布于 2009-12-10 21:57:00
wuzhouhong [专家分:10890]  发布于 2009-12-10 21:57:00				
				给你个思路:
select * from 表1 where .F. into cursor temp_table1
select 日期 distinc from 表1 order by 日期 DESC into cursor temp_table2
   scan
      Current_Date=temp_table2.日期
      select * from 表1 where 日期=Current_Date order by 金额 DESC into cursor temp_table3
      select * from cursor temp_table1  union select * from temp_table3 where reccount()<=10 into cursor temp_table1
      select temp_table2
   endscan
select temp_table1
brow
							 
						
				4 楼
				
					 jinlonggao [专家分:17130]  发布于 2009-12-26 21:08:00
jinlonggao [专家分:17130]  发布于 2009-12-26 21:08:00				
				select * from 表1 where .F. into table temp_table
select distinc 日期 from 表1 into cursor temp_table1
scan
  Current_Date=日期
  inseert innto temp_table select top 10 * from 表1 where 日期=Current_Date order by 金额 DESC        && 第一二个字中多余一个'e'和'n',执行时去掉
endscan
select temp_table
brow
							 
									
			
我来回复