问题陈述:
查询订单中总商品数190.
但是关联用户表后 将老客的购买商品数+新客购买的订单数相加.总数为196 多出来几个.
理论上 商品数 总大于订单数的.
关联语句
select sum(o.payment) amount,count(o.oid) order_num,count(distinct o.buyer_nick) buyer_cnt from order_info o join trade_info t on t.tid=o.tid join custom_info c on o.buyer_nick=c.nick and c.shop_nick=o.seller_nick and t.pay_time between '2012-07-14' and '2012-07-14 23:59:59' where o.seller_nick='xxx旗舰店'
将用户,购买的商品数,在两种查询条件下列出来,然后排序后做比较.找出异常的用户.
后查明因为 custom_info 中是在相同的seller_nick下才唯一.
实际上o.seller_nick已经定死了seller_nick 但是实际上没起作用.
增加c.shop_nick=t.buyer_nick 解决.
查询订单中总商品数190.
但是关联用户表后 将老客的购买商品数+新客购买的订单数相加.总数为196 多出来几个.
理论上 商品数 总大于订单数的.
关联语句
select sum(o.payment) amount,count(o.oid) order_num,count(distinct o.buyer_nick) buyer_cnt from order_info o join trade_info t on t.tid=o.tid join custom_info c on o.buyer_nick=c.nick and c.shop_nick=o.seller_nick and t.pay_time between '2012-07-14' and '2012-07-14 23:59:59' where o.seller_nick='xxx旗舰店'
将用户,购买的商品数,在两种查询条件下列出来,然后排序后做比较.找出异常的用户.
后查明因为 custom_info 中是在相同的seller_nick下才唯一.
实际上o.seller_nick已经定死了seller_nick 但是实际上没起作用.
增加c.shop_nick=t.buyer_nick 解决.