客户号 购买日期 销售好 金额246 2003-04-29 00:00:00.000 3166 177.00
246 2003-05-16 00:00:00.000 2389 42.00
246 2003-05-08 00:00:00.000 2168 85.00
248 2003-04-30 00:00:00.000 3172 997.00
248 2003-04-17 00:00:00.000 3043 550.00
249 2003-07-23 00:00:00.000 858 315.00
249 2003-07-31 00:00:00.000 907 204.00
250 2003-04-20 00:00:00.000 3070 343.00
250 2003-04-25 00:00:00.000 3126 29.00
253 2003-04-29 00:00:00.000 3162 271.00
254 2003-06-17 00:00:00.000 1513 244.00
254 2003-06-24 00:00:00.000 1676 77.00
254 2003-06-19 00:00:00.000 1624 12.60
写个语句实现 最近一段时间(比如30天)没有销售记录,而且最近一次(注意,最近一次)的销售金额小于一个值(比如200)的客户号
注意:每个客户有很多条销售记录
246 2003-05-16 00:00:00.000 2389 42.00
246 2003-05-08 00:00:00.000 2168 85.00
248 2003-04-30 00:00:00.000 3172 997.00
248 2003-04-17 00:00:00.000 3043 550.00
249 2003-07-23 00:00:00.000 858 315.00
249 2003-07-31 00:00:00.000 907 204.00
250 2003-04-20 00:00:00.000 3070 343.00
250 2003-04-25 00:00:00.000 3126 29.00
253 2003-04-29 00:00:00.000 3162 271.00
254 2003-06-17 00:00:00.000 1513 244.00
254 2003-06-24 00:00:00.000 1676 77.00
254 2003-06-19 00:00:00.000 1624 12.60
写个语句实现 最近一段时间(比如30天)没有销售记录,而且最近一次(注意,最近一次)的销售金额小于一个值(比如200)的客户号
注意:每个客户有很多条销售记录
解决方案 »
- 求 锁屏幕的源码 类似于网吧 万象 美萍
- 如何将 Image2 中与 Image1 中不同的部分提取并无闪烁的覆盖到 Image1 中相同的位置?
- 为了爱,我在广州-上海徘徊,值得吗?
- 请问如何循环读入文本文件的内容???
- ab表的问题
- self指代的是啥?
- 当FORM1窗体最小化时
- 高分------如何获取主窗口外的鼠标坐标点 并能控制鼠标到指定的坐标?
- 哪个大哥帮我吧下面的PASCAL代码修改成标准的DELPHI的代码啊!急用!!
- 请问各位如何将自己开发的软件上传服务器供人下摘???????????
- 急!在XP下编写的程序在98下显示不正常,字体大了好多,是什么问题?
- 关于表和DBGrid的操作~UP有分
delete from #ttt where day(getdate()-rq)<30 //剩下的都是大于30天的
select khh from table where khh in (select khh from #ttt) and je<200这三条可以放在一个语句里面的,不过就是效率比较低。
where (select top1 from a order by purcharse_date desc)<200i'm in bar, do not know wheather it can work.try yourself.
一个是销售记录表就是你列的表了名字叫s好了select custom.客户号 from custom
where 客户号 not in
(select 客户号 from s where datediff(day, 购买日期, getdate)<30)
and
客户号 in
(select 客户号 from s,(select 客户号,max(购买日期) as "购买日期" from s group by 客户号) ss where s.金额<200 and s.客户号=ss.客户号 and s.购买日期=ss.购买日期)行拉
不过估计select 客户号,max(购买日期) as "购买日期" from s group by 客户号) ss 得换成视图ss因为from里不能写select
(
@days int,
@MinSellPrice numeric(13,4)
)
as
select custno from cust where custno not in
(select distinct custno from sells where datediff(day,buyDate,GetDate()) < @Days) a
and custno in (select custno from sells where sellPrice<@MinSellPrice)
一个是销售记录表就是你列的表了名字叫s好了select custom.客户号 from custom
where 客户号 not in
(select 客户号 from s where datediff(day, 购买日期, getdate)<30 )
and exists(select top 1 * from s where s.客户号=custom.客户号 and s.金额<200 order by purcharse_date desc)
.close;
.sql.clear;
.sql.add( select 客户号 from a where 客户号 not in (select 客户号 from a where datediff(day, 购买日期, getdate())<30 ));
.open;
with query2 do
.close;
.sql.clear;
.sql.add( select * from a where 客户号=query1.field(0).asstring and 金额<200 order by purcharse_date desc );
.open
你的方法正确,接分!
但这我有点不太名台可以将一下思想吗。
exists(select top 1 * from s where s.客户号=custom.客户号 and s.金额<200 order by purcharse_date desc没有s.客户号=custom.客户号 ,就不行