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

MySQL Kiri bergabung dengan masalah kueri gabung silang

Coba ini:

select t4.AppointmentTimeID, t4.AppointmentDate,ifnull(t5.NumberOfApplicants,0)
from
    (select distinct t2.AppointmentTimeID, t1.AppointmentDate
  from tbl_appointmentschedule_details t2 join (select t.AppointmentDate from (
SELECT adddate('2015-10-16', @rownum := @rownum + 1) as 'AppointmentDate' FROM tbl_appointments
JOIN (SELECT @rownum := -1) r
LIMIT 31
) t 
where t.AppointmentDate between '2015-10-16' and '2015-10-18') t1)  t4
left join 
    (SELECT t2.AppointmentTimeID,t1.AppointmentDate,sum(t1.NumberOfApplicants) as 'NumberOfApplicants'
    FROM tbl_appointmentschedule_details t2
    LEFT JOIN tbl_appointments t1 on t2.AppointmentTimeID=t1.AppointmentTimeID
    WHERE t1.AppointmentStatus='Pending' AND t1.AvailableInMarket=0
    GROUP BY t2.AppointmentTimeID,t1.AppointmentDate) t5 
on t4.AppointmentDate=t5.AppointmentDate and t4.AppointmentTimeID=t5.AppointmentTimeID
having t4.AppointmentTimeID!=0
order by t4.AppointmentDate,t4.AppointmentTimeID;



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. REPLACE case-insensitive di MySQL?

  2. Pembatas di MySQL

  3. Periksa apakah tabel MySQL ada tanpa menggunakan pilih dari sintaks?

  4. JDBC, MySQL:memasukkan bit ke dalam kolom BIT(M!=1)

  5. Peringatan:mysqli_connect():(HY000/2002):Tidak ada file atau direktori seperti itu