简单的sql在线等`~ select * from 表 twhere 日期字段 in(select distinct top 2 日期字段 from 表 where 客户=t.客户 order by 日期字段 desc)order by 客户 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from 表 twhere 日期字段 in(select top 2 日期字段 from 表 where 客户=t.客户 order by 日期字段 desc)order by 客户 select * from 表 twhere (select count(distinct 时间字段) from 表 where 客户=t.客户 and 时间字段 >t.时间字段)<2 group by 客户 上面的表t是什么?select id,cuscode,cusprice,pricedate from Price 查询出来的结果cuscode cusprice pricedate id14 458.00 2005-07-01 00:00:00.000 5614 630.00 2005-07-01 00:00:00.000 6115 510.00 2005-07-01 00:00:00.000 6215 707.00 2005-07-01 00:00:00.000 6315 563.00 2005-07-01 00:00:00.000 6517 720.00 2005-07-01 00:00:00.000 6610 674.00 2005-07-01 00:00:00.000 7010 650.00 2005-07-01 00:00:00.000 7110 650.00 2005-07-01 00:00:00.000 7521 318.34 2005-07-01 00:00:00.000 7624 517.00 2005-07-01 00:00:00.000 8125 600.00 2005-07-01 00:00:00.000 8226 700.00 2005-07-01 00:00:00.000 8527 540.00 2005-07-01 00:00:00.000 8627 720.00 2005-07-01 00:00:00.000 8733 642.00 2005-07-01 00:00:00.000 9134 569.00 2005-07-01 00:00:00.000 9235 626.97 2005-07-01 00:00:00.000 9335 620.00 2005-07-01 00:00:00.000 9435 660.00 2005-07-01 00:00:00.000 9535 450.00 2005-07-01 00:00:00.000 9636 664.00 2005-07-01 00:00:00.000 9736 760.00 2005-07-01 00:00:00.000 9837 590.00 2005-07-01 00:00:00.000 9938 340.00 2005-07-01 00:00:00.000 10038 361.90 2005-07-01 00:00:00.000 10138 380.00 2005-07-01 00:00:00.000 10238 422.50 2005-07-01 00:00:00.000 10338 253.00 2005-07-01 00:00:00.000 10439 345.00 2005-07-01 00:00:00.000 10539 390.00 2005-07-01 00:00:00.000 10640 656.00 2005-07-01 00:00:00.000 10740 660.00 2005-07-01 00:00:00.000 10840 660.00 2005-07-01 00:00:00.000 11041 620.00 2005-07-01 00:00:00.000 11141 760.00 2005-07-01 00:00:00.000 11241 660.00 2005-07-01 00:00:00.000 11342 370.00 2005-07-01 00:00:00.000 11442 433.00 2005-07-01 00:00:00.000 11542 433.00 2005-07-01 00:00:00.000 11643 430.00 2005-07-01 00:00:00.000 11745 450.00 2005-07-01 00:00:00.000 12146 740.00 2005-07-01 00:00:00.000 12646 740.00 2005-07-01 00:00:00.000 12747 580.00 2005-07-01 00:00:00.000 12847 490.00 2005-07-01 00:00:00.000 12948 440.00 2005-07-01 00:00:00.000 13049 594.00 2005-07-01 00:00:00.000 13149 578.00 2005-07-01 00:00:00.000 132 select top 2 from 表名 a,表名 bwhere a.客户名=b.客户名 group by 客户名orderby 日期字段 我认为是这样。。..... --try (T为表别名)select * from Price twhere pricedate in(select distinct top 2 pricedate from Price where cuscode=t.cuscode order by pricedate desc)order by cuscode where 客户=t.客户是什么意思?难道要列举所有的客户? zlp321002(人生没有理想,那和咸鱼还有什么两样) 大侠的OK了,,感谢感谢~~ 有没有道理:where子句使用参数查询会导致索引失效? 请教一个sql语句 关于读取表中最多数量的SQL语句 救命啊!!!求一条SQL语句高手请帮忙!!! like查询问题 想编一个自定义函数,不知有何返回值表示执行成功还是没有执行成功,0表示成功,1表示不成功好呢?还是1表示成功,0表示不成功呢? 求一个简单的查询 初学者sql语句问题 如何得到本机上所有sql的实例名? table的field不能识别SQL SERVER表的字段怎么办? 想写一个带参数的存储过程来读取数据,长时间没有写了忘记了 求助!!!!SQL SERVER 2000安装程序配置服务器失败
from 表 t
where 日期字段 in(select top 2 日期字段
from 表
where 客户=t.客户
order by 日期字段 desc)
order by 客户
from 表 t
where (select count(distinct 时间字段) from 表 where 客户=t.客户 and 时间字段 >t.时间字段)<2 group by 客户
上面的表t是什么?
select id,cuscode,cusprice,pricedate from Price
查询出来的结果cuscode cusprice pricedate id
14 458.00 2005-07-01 00:00:00.000 56
14 630.00 2005-07-01 00:00:00.000 61
15 510.00 2005-07-01 00:00:00.000 62
15 707.00 2005-07-01 00:00:00.000 63
15 563.00 2005-07-01 00:00:00.000 65
17 720.00 2005-07-01 00:00:00.000 66
10 674.00 2005-07-01 00:00:00.000 70
10 650.00 2005-07-01 00:00:00.000 71
10 650.00 2005-07-01 00:00:00.000 75
21 318.34 2005-07-01 00:00:00.000 76
24 517.00 2005-07-01 00:00:00.000 81
25 600.00 2005-07-01 00:00:00.000 82
26 700.00 2005-07-01 00:00:00.000 85
27 540.00 2005-07-01 00:00:00.000 86
27 720.00 2005-07-01 00:00:00.000 87
33 642.00 2005-07-01 00:00:00.000 91
34 569.00 2005-07-01 00:00:00.000 92
35 626.97 2005-07-01 00:00:00.000 93
35 620.00 2005-07-01 00:00:00.000 94
35 660.00 2005-07-01 00:00:00.000 95
35 450.00 2005-07-01 00:00:00.000 96
36 664.00 2005-07-01 00:00:00.000 97
36 760.00 2005-07-01 00:00:00.000 98
37 590.00 2005-07-01 00:00:00.000 99
38 340.00 2005-07-01 00:00:00.000 100
38 361.90 2005-07-01 00:00:00.000 101
38 380.00 2005-07-01 00:00:00.000 102
38 422.50 2005-07-01 00:00:00.000 103
38 253.00 2005-07-01 00:00:00.000 104
39 345.00 2005-07-01 00:00:00.000 105
39 390.00 2005-07-01 00:00:00.000 106
40 656.00 2005-07-01 00:00:00.000 107
40 660.00 2005-07-01 00:00:00.000 108
40 660.00 2005-07-01 00:00:00.000 110
41 620.00 2005-07-01 00:00:00.000 111
41 760.00 2005-07-01 00:00:00.000 112
41 660.00 2005-07-01 00:00:00.000 113
42 370.00 2005-07-01 00:00:00.000 114
42 433.00 2005-07-01 00:00:00.000 115
42 433.00 2005-07-01 00:00:00.000 116
43 430.00 2005-07-01 00:00:00.000 117
45 450.00 2005-07-01 00:00:00.000 121
46 740.00 2005-07-01 00:00:00.000 126
46 740.00 2005-07-01 00:00:00.000 127
47 580.00 2005-07-01 00:00:00.000 128
47 490.00 2005-07-01 00:00:00.000 129
48 440.00 2005-07-01 00:00:00.000 130
49 594.00 2005-07-01 00:00:00.000 131
49 578.00 2005-07-01 00:00:00.000 132
where a.客户名=b.客户名
group by 客户名
orderby 日期字段
我认为是这样。。.....
from Price t
where pricedate in(select distinct top 2 pricedate
from Price
where cuscode=t.cuscode
order by pricedate desc)
order by cuscode
是什么意思?
难道要列举所有的客户?
感谢感谢~~