查出兑换商品的排名

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



  1. 查出兑换商品的排名
  2. SELECT ig.goods_id,ig.exchange_integral,ig.goods_thumb,og.integral_count FROM (
  3. SELECT g.goods_id, g.goods_thumb,eg.exchange_integral
  4. FROM `s513304db0`.`ecs_exchange_goods` AS eg, `s513304db0`.`ecs_goods` AS g
  5. WHERE eg.is_exchange =1
  6. AND eg.goods_id = g.goods_id
  7. AND g.is_on_sale =1
  8. AND g.is_delete =0
  9. ) AS ig,
  10. (
  11. SELECT count( * ) AS integral_count, og.goods_id
  12. FROM `s513304db0`.`ecs_order_goods` AS og, `s513304db0`.`ecs_order_info` AS oi
  13. WHERE og.order_id = oi.order_id
  14. AND oi.integral <>0
  15. AND oi.integral_money =0
  16. GROUP BY og.goods_id
  17. ) AS og WHERE ig.goods_id = og.goods_id ORDER BY og.integral_count DESC
  18. 子查询,查出在线可以兑换的商品
  19. SELECT g.goods_id, g.goods_thumb, eg.exchange_integral
  20. FROM `s513304db0`.`ecs_exchange_goods` AS eg, `s513304db0`.`ecs_goods` AS g
  21. WHERE eg.is_exchange =1
  22. AND eg.goods_id = g.goods_id
  23. AND g.is_on_sale =1
  24. AND g.is_delete =0
  25. LIMIT 0 , 30
  26. 子查询,查出订单中属于积分兑换的商品
  27. SELECT count( * ) AS integral_count, og.goods_id
  28. FROM `s513304db0`.`ecs_order_goods` AS og, `s513304db0`.`ecs_order_info` AS oi
  29. WHERE og.order_id = oi.order_id
  30. AND oi.integral <>0
  31. AND oi.integral_money =0
  32. GROUP BY og.goods_id
  33. LIMIT 0 , 30

  34. /**
  35. * 获得兑换商品排名 liangfang add
  36. *
  37. * @accesspublic
  38. * @paramstring$children
  39. * @returnarray
  40. */
  41. function get_exchange_goods_top( $num)
  42. {
  43. $sql='SELECT ig.goods_id,ig.goods_name,ig.exchange_integral,ig.goods_thumb,og.integral_count FROM (
  44. SELECT g.goods_id, g.goods_thumb,g.goods_name,eg.exchange_integral
  45. FROM '.$GLOBALS['ecs']->table('exchange_goods').' AS eg, '.$GLOBALS['ecs']->table('goods').' AS g
  46. WHERE eg.is_exchange =1
  47. AND eg.goods_id = g.goods_id
  48. AND g.is_on_sale =1
  49. AND g.is_delete =0

  50. ) AS ig,
  51. (
  52. SELECT count( * ) AS integral_count, og.goods_id
  53. FROM '.$GLOBALS['ecs']->table('order_goods').' AS og, '.$GLOBALS['ecs']->table('order_info').' AS oi
  54. WHERE og.order_id = oi.order_id
  55. AND oi.integral <>0
  56. AND oi.integral_money =0
  57. GROUP BY og.goods_id

  58. ) AS og WHERE ig.goods_id = og.goods_id ORDER BY og.integral_count DESC';

  59. if($num > 0)
  60. {
  61. $sql.=" LIMIT $num";
  62. }
  63. $integral_goods=$GLOBALS['db']->getAll($sql);



  64. return $integral_goods;
  65. }
复制代码