注册 登录
编程论坛 SQL Server论坛

查询09年销费并且在10年有过销费的会员

hksyw 发布于 2011-06-16 17:15, 547 次点击
销售流水表如下:(只有这一张表)
流水字段        会员卡号    会员名称
09001           1001        张三
09002           1002        李四
10001           1001        张三
10002           1004        马六

09001前两个字代表09年
10001前两个字代表10年

怎样查询出来09年销费过并且10年也销费过的会员
在线等谢谢
3 回复
#2
go20112011-06-16 18:33
select distinct 会员卡号,会员名称 from 销售流水表
where (会员卡号 in (select 会员卡号 from 销售流水表
 where substring(流水字段,1,2)='09'))
and (会员卡号 in (select 会员卡号 from 销售流水表
 where substring(流水字段,1,2)='10'))
#3
yuqiaoqiao192011-06-17 13:55
select distinct * from 销售流水表
where(
(会员卡号 in(select 会员卡号 from 销售流水表 where 流水帐号 is like "09%")
=
(会员卡号 in(select 会员卡号 from 销售流水表 where 流水帐号 is like "10%")
)

#4
panyanpan2011-06-18 09:05
select distinct 会员卡号,会员名称 from 销售流水表
where 会员卡号 in(select 会员卡号 from 销售流水表 where 流水帐号 like '09%')
and 会员卡号 in(select 会员卡号 from 销售流水表 where 流水帐号 like '10%')
1