想了一天了,被自己的思维限制住了,大家帮个忙吧......用户表:
userId,name
记录表:
recordId,userId,createTime,businessTime
交易状态表:
strutsId,recordId,name,value
例如我要 检索.......2009年8月 所有未交易过的人的记录 如何写sql 呢...........
select * from 用户表 where userId not in(select userId from 记录表 where MONTH(businessTime) = 8)这样 检索出来 的记录不准确呀............例如 1月未交易的用户也 检索出来了...........请问如何设计呢?最好能检索出带 交易状态的...........太累了 晕乎乎的.....求助了.....

解决方案 »

  1.   

    select a.userId,a.[name],c.strutsId,c.[name],c.[value]
    from 用户表 a join 记录表 b on a.userId=b.userId
          join 交易状态表 c on b.recordId=c.recordId
    where a.userId not in (select userId from 记录表 where convert(varchar(7),businessTime,120)='2009-08')
      

  2.   

    select a.userId,a.[name],c.strutsId,c.[name],c.[value]
    from 用户表 a join 记录表 b on a.userId=b.userId
          join 交易状态表 c on b.recordId=c.recordId
    where a.userId not in 
    (select userId from 记录表 where convert(varchar(7),businessTime,120)='2009-08')
      

  3.   


    你的意思是只要8月份,没有交易的人了!select a.userId,a.[name],c.strutsId,c.[name],c.[value]
    from 用户表 a join 记录表 b on a.userId=b.userId
              join 交易状态表 c on b.recordId=c.recordId
    where a.userId not in 
    (select userId from 记录表 where convert(varchar(7),businessTime,120)='2009-08')
    and convert(varchar(7),businessTime,120)='2009-08'
      

  4.   

    用户表:
    userId,name
    数据:
    1,张三
    2,李四
    3,王五
    4,赵六记录表:
    recordId,userId,createTime,businessTime,recordId
    1,1,2009-02-07,2009-02-07,1
    2,2,2009-04-02,2009-04-02,0
    3,3,2009-05-07,2009-05-07,0
    4,4,2009-07-07,2009-07-07,1交易状态表:
    strutsId,name,value 
    0,未成功,0
    1,成功,1
    例如我想查询5月所有没有发放的 应该出来的是 1 2 4的ID
    ................
      

  5.   

    那如果改成:
    用户表:
    userId,name
    记录表:
    recordId,userId,createTime,交易开始时间,交易结束时间呢..........
    bettem 应该怎么写好呢?需求同上...