如何使用子句(where,and,not)sql

时间:2016-01-13 06:15:12

标签: mysql

我有这样的表absen:

I have table absen

表格itungharian和coloumn这样:

  

id_itung | id |总计| itungtgl   (没有数据)

并像这样查询连接:

 SELECT
      count(tgl) AS total,
      absen.id,
      pegawai.nama,
      pegawai.bagian,
      pegawai.bagian,
      pegawai.tglmasuk,
      gaji.jenis_gaji,
      gaji.jumlah, 
      itungharian.id AS id2,
      itungharian.itungtgl,
      CASE
           WHEN (weekday(tgl) <=3 )
           THEN date(tgl + INTERVAL(3 - weekday(tgl)) DAY)
           ELSE date(tgl + INTERVAL(3 + 7 - weekday(tgl)) DAY)
           END AS tglitung
FROM
      absen
JOIN
      pegawai ON pegawai.id = absen.id
JOIN
      gaji ON gaji.id = pegawai.id
LEFT JOIN
      itungharian ON itungharian.id = absen.id
WHERE
      absen.status = 'm'
GROUP BY
      absen.id,
      tglitung

并显示此信息 table join

所以如果像cloumn id(表absen)上的值与itungharian.tgl和tglitung(结果大小写时)相同,itungharian.itungtgl在连接表中显示

我尝试过像这样的SQL:

 SELECT
      count(tgl) AS total,
      absen.id,
      pegawai.nama, 
      pegawai.bagian,
      pegawai.bagian,
      pegawai.tglmasuk,
      gaji.jenis_gaji, 
      gaji.jumlah,
      itungharian.id AS id2,
      itungharian.itungtgl,
      CASE
           WHEN (weekday(tgl) <= 3)
           THEN date(tgl + INTERVAL(3 - weekday(tgl)) DAY)
           ELSE date(tgl + INTERVAL(3 + 7 - weekday(tgl)) DAY)
           END AS tglitung
 FROM
      absen
 JOIN
      pegawai ON pegawai.id = absen.id
 JOIN
      gaji ON gaji.id = pegawai.id
 LEFT JOIN
      itungharian ON itungharian.id = absen.id
 WHERE
      absen.status = 'm' 
 AND
      NOT (CASE WHEN (weekday(tgl) <= 3)
           THEN DATE(tgl + INTERVAL(3 - weekday(tgl)) DAY)
           ELSE DATE(tgl + INTERVAL(3 + 7 - weekday(tgl)) DAY)END) = itungharian.itungtgl 
 AND
      NOT absen.id = itungharian.id
 GROUP BY
      absen.id,
      tglitung

但MySQL返回一个空结果集(即零行)。

0 个答案:

没有答案