Advertisement
cdsatrian

Tanaman

Dec 3rd, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.58 KB | None | 0 0
  1. SELECT
  2.   a.nama_tanaman,
  3.   a.stok
  4.     +SUM(
  5.       IF(
  6.         DATE_FORMAT(c.tgl_tanaman_masuk,'%Y%m')<=DATE_FORMAT($bulanlalu,'%Y%m'),
  7.         jumlah_tanaman_masuk,
  8.         0
  9.       )
  10.     )
  11.     -SUM(
  12.       IF(
  13.         DATE_FORMAT(d.tgl_pengurangan_tanaman,'%Y%m')<=DATE_FORMAT($bulanlalu,'%Y%m'),
  14.         jumlah_pengurangan_tanaman,
  15.         0
  16.       )
  17.     ) AS bulanlalu,
  18.   c.tgl_tanaman_masuk,
  19.   c.asal,
  20.   SUM(
  21.     IF(
  22.       DATE_FORMAT(c.tgl_tanaman_masuk,'%Y%m')=DATE_FORMAT($bulanini,'%Y%m'),
  23.       jumlah_tanaman_masuk,
  24.       0
  25.     )
  26.   ) AS jumlah,
  27.   SUM(
  28.     IF(
  29.         (
  30.           DATE_FORMAT(d.tgl_pengurangan_tanaman,'%Y%m')=DATE_FORMAT($bulanini,'%Y%m')
  31.           AND d.jenis_pengurangan='mati'
  32.         ),
  33.         jumlah_pengurangan_tanaman,
  34.         0
  35.        )
  36.      ) AS mati,
  37.   SUM(
  38.     IF(
  39.         (
  40.           DATE_FORMAT(d.tgl_pengurangan_tanaman,'%Y%m')=DATE_FORMAT($bulanini,'%Y%m')
  41.           AND d.jenis_pengurangan='distribusi'
  42.         ),
  43.         jumlah_pengurangan_tanaman,
  44.         0
  45.        )
  46.      ) AS distribusi,
  47.   a.stok
  48.     +SUM(
  49.       IF(
  50.         DATE_FORMAT(c.tgl_tanaman_masuk,'%Y%m')=DATE_FORMAT($bulanini,'%Y%m'),
  51.         jumlah_tanaman_masuk,
  52.         0
  53.       )
  54.     )
  55.     -SUM(
  56.       IF(
  57.         DATE_FORMAT(d.tgl_pengurangan_tanaman,'%Y%m')=DATE_FORMAT($bulanini,'%Y%m'),
  58.         jumlah_pengurangan_tanaman,
  59.         0
  60.       )
  61.     )AS total_bulanini,
  62. FROM tanaman a
  63.   JOIN jenis__tanaman b USING(id_jenis_tanaman)
  64.   JOIN tanaman_masuk c USING(id_tanaman)
  65.   JOIN pengurangan_tanaman d USING(id_tanaman)
  66. GROUP BY a.id_tanaman
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement