序列号查询.sql 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. select * from ((SELECT
  2. t4.agentnum,
  3. t5.contact,
  4. t5.phonenumber,
  5. t5.address,
  6. case when ifnull(t6.cardno,'')='' then '未安装' else '已安装' end isinstalled,
  7. t6.cardno,
  8. t6.begdate,
  9. t6.enddate,
  10. t6.isvoid,
  11. t7.sa_customersid,
  12. t1.sku,
  13. t1.sa_itemskuid,
  14. t2.itemid,
  15. t2.itemno,
  16. t2.itemname,
  17. t2.model,
  18. t2.spec,
  19. t3.unitname,
  20. t7.name as customername,
  21. t7.phonenumber as customerphonenumber
  22. FROM sa_itemsku t1
  23. LEFT JOIN plm_item t2 ON t1.itemid = t2.itemid AND t1.siteid = t2.siteid
  24. LEFT JOIN plm_unit t3 ON t3.unitid = t2.unitid AND t3.siteid = t2.siteid
  25. LEFT JOIN sa_agents t4 ON t4.sys_enterpriseid = t1.sys_enterpriseid
  26. AND t4.siteid = t1.siteid
  27. LEFT JOIN sys_enterprise t5 ON t5.sys_enterpriseid = t4.sys_enterpriseid
  28. AND t5.siteid = t4.siteid
  29. LEFT JOIN sa_warrantycard t6 ON t6.sku = t1.sku AND t1.siteid = t6.siteid
  30. LEFT JOIN sa_customers t7 ON t6.sa_customersid = t7.sa_customersid
  31. AND t6.siteid = t7.siteid
  32. WHERE t1.siteid =$siteid$
  33. AND t1.sys_enterpriseid = $sys_enterpriseid$
  34. ORDER BY t1.sa_itemskuid)
  35. UNION ALL
  36. (SELECT
  37. t4.agentnum,
  38. t5.contact,
  39. t5.phonenumber,
  40. t5.address,
  41. case when ifnull(t6.cardno,'')='' then '未安装' else '已安装' end isinstalled,
  42. t6.cardno,
  43. t6.begdate,
  44. t6.enddate,
  45. t6.isvoid,
  46. t7.sa_customersid,
  47. t1.sku,
  48. t1.sa_itemskuid,
  49. t2.itemid,
  50. t2.itemno,
  51. t2.itemname,
  52. t2.model,
  53. t2.spec,
  54. t3.unitname,
  55. t7.name as customername,
  56. t7.phonenumber as customerphonenumber
  57. FROM sa_itemsku t1
  58. INNER JOIN sa_agents a ON t1.sa_agentsid = a.sa_agentsid
  59. AND t1.siteid = a.siteid
  60. LEFT JOIN plm_item t2 ON t1.itemid = t2.itemid AND t1.siteid = t2.siteid
  61. LEFT JOIN plm_unit t3 ON t3.unitid = t2.unitid AND t3.siteid = t2.siteid
  62. LEFT JOIN sa_agents t4 ON t4.sys_enterpriseid = t1.sys_enterpriseid
  63. AND t4.siteid = t1.siteid
  64. LEFT JOIN sys_enterprise t5 ON t5.sys_enterpriseid = t4.sys_enterpriseid
  65. AND t5.siteid = t4.siteid
  66. LEFT JOIN sa_warrantycard t6 ON t6.sku = t1.sku AND t1.siteid = t6.siteid
  67. LEFT JOIN sa_customers t7 ON t6.sa_customersid = t7.sa_customersid
  68. AND t6.siteid = t7.siteid
  69. WHERE t1.siteid = $siteid$
  70. AND a.sys_enterpriseid =$sys_enterpriseid$
  71. AND t1.sys_enterpriseid != $sys_enterpriseid$
  72. ORDER BY t1.sa_itemskuid)) t1 where $where$