Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. SET SESSION group_concat_max_len = 1000000;
  2.  
  3. SET @sql = NULL;
  4. SELECT
  5. GROUP_CONCAT(DISTINCT
  6. CONCAT(
  7. 'MAX(CASE WHEN f1.Tank_ID= ''',
  8. f1.Tank_ID,
  9. ''' THEN nf1.'Receipt' END) AS '
  10. f1.Tank
  11. )
  12. )INTO @sql
  13. FROM
  14. tank_details AS nf1
  15. RIGHT JOIN
  16. tank AS f1 ON f1.Tank_ID = nf1.Tank_ID
  17. group by DATE(`Date`);
  18.  
  19. Tank_ID Tank
  20. 1 Tank 1
  21. 2 Tank 2
  22. 3 Tank 3
  23. 4 Tank 4
  24. 5 Tank 5
  25.  
  26. Tank_ID Receipt Date
  27. 1 1000 2019-07-10
  28. 2 2000 2019-07-10
  29. 3 3000 2019-07-10
  30. 1 0 2019-07-10
  31. 1 0 2019-07-15
  32. 3 0 2019-07-15
  33. 2 0 2019-07-15
  34. 3 0 2019-07-15
  35. 1 250 2019-07-15
  36. 2 200 2019-07-15
  37. 3 800 2019-07-15
  38. 1 250 2019-07-15
  39. 4 350 2019-07-15
  40. 1 0 2019-07-20
  41. 2 0 2019-07-20
  42. 3 0 2019-07-20
  43. 4 0 2019-07-20
  44. 1 300 2019-07-20
  45. 2 1200 2019-07-20
  46. 3 1400 2019-07-20
  47. 4 900 2019-07-20
  48. 5 20 2019-07-20
  49. 1 500 2019-07-20
  50.  
  51. Date Receipt Tank 1 Tank 2 Tank 3 Tank 4 Tank 5
  52. 2019-07-10 6000 1000 2000 3000 NULL NULL
  53. 2019-07-15 1850 500 200 800 350 NULL
  54. 2019-07-20 4320 800 1200 1400 900 20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement