T_A 表示所有商品,T_B表示所有购买者纪录,
现在要找出  T_A 添加时间addtime 最新的 10条记录,并且 关联 T_B 中最后一个购买者 custom列表,找出前十条

解决方案 »

  1.   

    参考下贴中的多种方法http://blog.csdn.net/acmain_chm/article/details/4126306
    [征集]分组取最大N条记录方法征集,及散分....
      

  2.   

    设T_A与T_B是靠商品号prod_id关联,
    select *
    from (select * from T_A order by add_time desc limit 10) A /* 先找到 最新10条 */
    join (select prod_id, max(order_time) max_order_time from T_B) B using (A.prod_id = T_B.prod_id) /* 找到相应产品的最大下单时间 */
    join (select customer_id from T_B) B2 using (B.prod_id = B2.prod_id and B.max_order_time = B2.order_time) /* 连接取customer_id */