促销方案列表查询.sql 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. select t.* from (SELECT t1.promnum,
  2. t1.sa_promotionid,
  3. t1.promname,
  4. t1.remarks,
  5. t1.type,
  6. t1.sa_accountclassid,
  7. t1.sa_brandid,
  8. t1.tradefield,
  9. t2.brandname,
  10. t3.accountno,
  11. t3.accountname
  12. FROM sa_promotion t1
  13. LEFT JOIN sa_brand t2 ON t1.sa_brandid = t2.sa_brandid
  14. AND t1.siteid = t2.siteid
  15. LEFT JOIN sa_accountclass t3 ON t1.sa_accountclassid = t3.sa_accountclassid
  16. AND t1.siteid = t3.siteid
  17. where t1.siteid = $siteid$
  18. and t1.status = '发布'
  19. and t1.authmethod = 0
  20. and exists(select 1
  21. from sa_promotion_auth t2
  22. where t1.siteid = t2.siteid
  23. and t1.sa_promotionid = t2.sa_promotionid
  24. and t2.sys_enterpriseid = $sys_enterpriseid$)
  25. union all
  26. SELECT t1.promnum,
  27. t1.sa_promotionid,
  28. t1.promname,
  29. t1.remarks,
  30. t1.type,
  31. t1.sa_accountclassid,
  32. t1.sa_brandid,
  33. t1.tradefield,
  34. t2.brandname,
  35. t3.accountno,
  36. t3.accountname
  37. FROM sa_promotion t1
  38. LEFT JOIN sa_brand t2 ON t1.sa_brandid = t2.sa_brandid
  39. AND t1.siteid = t2.siteid
  40. LEFT JOIN sa_accountclass t3 ON t1.sa_accountclassid = t3.sa_accountclassid
  41. AND t1.siteid = t3.siteid
  42. where t1.siteid = $siteid$
  43. and t1.status = '发布'
  44. and t1.authmethod = 1
  45. and not exists(select 1
  46. from sa_promotion_auth t2
  47. where t1.siteid = t2.siteid
  48. and t1.sa_promotionid = t2.sa_promotionid
  49. and t2.sys_enterpriseid = $sys_enterpriseid$)) t where $where$