getElecList.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. SELECT
  2. DATE_FORMAT(lastinput.date, '%Y-%m-%d') as dateFormat,
  3. lastinput.*,
  4. e.empname putName,
  5. m.lastAmount aAmount,
  6. m.startAmount,
  7. m.useType,
  8. p.name pastureName,
  9. de.name departName,
  10. p.id AS pastureId2,
  11. m.id AS measureId2,
  12. m.Multiple,
  13. m.Multiple rate,
  14. lastinput.elecConsumption consumption,
  15. m.meterNumber AS formNumber,
  16. m.meterName AS formName,
  17. e.empname employeName1,
  18. lastinput.price price1
  19. FROM
  20. measure m
  21. LEFT JOIN (
  22. SELECT
  23. *
  24. FROM
  25. electricity
  26. WHERE
  27. id =(
  28. SELECT
  29. MAX(w.`id`) id
  30. FROM
  31. electricity w
  32. WHERE
  33. electricity.measureId = w.measureId
  34. )
  35. ) lastinput ON lastinput.measureId = m.id
  36. INNER JOIN pasture p ON m.pastureId = p.id
  37. left JOIN department de ON m.departmentId = de.id
  38. LEFT JOIN emp e ON e.id = lastinput.`employeId`
  39. where
  40. (
  41. lastinput.elecName like concat("%", ?, "%")
  42. or ? = ''
  43. )
  44. and (
  45. lastinput.elecNumber like concat("%", ?, "%")
  46. or ? = ''
  47. )
  48. and (
  49. m.useType like concat("%", ?, "%")
  50. or ? = ''
  51. )
  52. and (
  53. p.name = ?
  54. or ? = '现代牧业'
  55. )
  56. and (
  57. de.name = ?
  58. or ? = ''
  59. )
  60. and (
  61. date_format(lastinput.date, '%Y-%m-%d') = ?
  62. or ? = ''
  63. )
  64. and m.meterType = '电表'
  65. and lastinput.isDel = '0'
  66. order by
  67. m.meterNumber