表1:商品销售表(GoodsOper)
字段:ID(自动编号),Money(现金收费),Card(会员卡收费),SellDate(消费日期),Re(备注)表2:商品销售明细表(GoodsCons)
字段:ConsID(编号,对应消费销售表的ID),ItemID(商品内部编号),GoodsPrice(销售价格)表3:商品表(Goods)
字段:ItemID(商品内部编号),GoodsID(商品编号),Name(商品名称)数据:
表1:ID,Money,Card,SellDate,Re
    1  10    20   2011-1-1 购买测试表2:consID,ItemID,GoodPrice
     1      1      20
     1      2      10
表3:ItemID,GoodsID,Name
     1      SP1  商品1
     2      SP2  商品2查询语句: select selldate,re,[money],card from goodsoper a,GoodsCons b where a.ID=b.ConsID查询结果
消费日期 现金收费 会员卡收费 备注
2011-1-1 10         20        购买测试
2011-1-1 10         20        购买测试多出一条记录,正确的语句应该怎么写呢

解决方案 »

  1.   

    select distinct selldate,re,[money],card from goodsoper a,GoodsCons b where a.ID=b.ConsID
      

  2.   

    select
     a.*
    from
     goodsoper a,GoodsCons b 
    where
     a.ID=b.ConsID
    group by
     a.selldate,a.re,a.[money],a.card 
      

  3.   

    select distinct selldate '消费日期',money1 '现金收取',card '会员卡收费',re '备注' from tb1 left join tb2
    on tb1.id=tb2.consid