Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Perbandingan INT tanpa pernyataan WHERE

Coba ini:

SELECT
  emp.name AS '## Name',
  (SELECT COUNT(*)     
   FROM project p JOIN employee e ON p.number = e.number
   WHERE e.name = emp.name 
     AND datediff(str_to_date(p.dateEnded, '%Y-%m-%d'), e.dateStarted) = 0
   ) AS 'Day 0'
  ,(SELECT COUNT(*)
    FROM project p JOIN employee e ON p.number = e.number
    WHERE e.name = emp.name 
      AND datediff(str_to_date(p.dateEnded, '%Y-%m-%d'), e.dateStarted) = 1
   ) AS 'Day 1'
  ,(SELECT COUNT(*)
    FROM project p JOIN employee e ON p.number = e.number
    WHERE e.name = emp.name 
      AND datediff(str_to_date(p.dateEnded, '%Y-%m-%d'), e.dateStarted) = 2
   ) AS 'Day 2'
  ,(SELECT COUNT(*)
    FROM project p JOIN employee e ON p.number = e.number
    WHERE e.name = emp.name 
      AND datediff(str_to_date(p.dateEnded, '%Y-%m-%d'), e.dateStarted) = 3
   ) AS 'Day 3'
  ,(SELECT COUNT(*)
    FROM project p JOIN employee e ON p.number = e.number
    WHERE e.name = emp.name 
      AND datediff(str_to_date(p.dateEnded, '%Y-%m-%d'), e.dateStarted) = 4
   ) AS 'Day 4'
  ,(SELECT COUNT(*)
    FROM project p JOIN employee e ON p.number = e.number
    WHERE e.name = emp.name 
      AND datediff(str_to_date(p.dateEnded, '%Y-%m-%d'), e.dateStarted) >= 5
   ) AS 'Day 5'
FROM employee emp
GROUP BY emp.name

Lihat Demo Fiddle SQL (- telah membuat beberapa asumsi pada data Anda berdasarkan info yang diberikan).



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bidang Wajib diisi tidak ada hasil

  2. REGEXP Dengan PDO Mysql

  3. java.sql.SQLException:Indeks Kolom di luar jangkauan, 0 <1

  4. ImportError:Tidak ada modul bernama mysql.connector menggunakan Python2

  5. Konfigurasi indeks MySQL