Her şeyden önce, bu soru, PHP ve MySQL getirmedi
Ben iki veritabanı tablo var:
People tablosu:
person_id | field_1 | field_2 | other_fields...
Ve Notes tablosu:
note_id | person_id | created_timestamp | other_fields...
The People table has a one to many relationship with the Notes table...
Everytime a note is created in the Notes table, a timestamp is attached to it, also a person_id foreign key is assigned.
Now...
I need to find all people who haven't had a note against them in the last 30 days.
The way I do it now is:
- Ayrı
person_idvecreated_timestamp>'time(31*86400)'(kesin değil .. Biliyorum, ama takım elbise ileNotestablosundan tüm notları alın benim ihtiyaçlarına) - Sonuçlar üzerinden ve geçici bir diziye
$tempiçinperson_ideklemek döngü Peopletablosundan tüm kayıtları alın- Her kayıt döngü ve mutlaka
person_id$tempile birin_array()karşılaştırması
Bu çok verimli değildir ve People veya Notes bir yeri vardır uygulamayı sakat.
Herkes bu daha iyi bir çözüm var. İdeal sadece tek bir SQL sorgusu kullanarak elde edilebilir bir şeydir.
Seyir için teşekkürler