簡體   English   中英

如何從表1中選擇還沒有付款條目的記錄?

[英]How to select record from table1 where there is no payment entry yet?

我在mysqli中有2個表,我想從table1中選擇所有客戶,其中table2中還沒有付款項或(特定日期)。

實際上,我正在使用php開發客戶付款系統,並想生成有關尚未按時提交分期付款的客戶的報告。

截止日期是每月的10號。 我該如何實現?

編輯以獲取更多詳細信息:1-在表1中,我有客戶的個人數據2-在表2中,分期付款項

客戶必須在每月的10號之前分期付款。 當客戶提交付款時,其條目將插入到table2中。

現在,我想通知客戶或報告尚未在本月的第10個(或任何到期日)之前提交其分期付款的客戶。

必須報告,以便恢復人員可以獲取遲到的客戶清單,以提交其分期付款或將提醒發送給客戶以進行即將到來的分期付款。

我的桌子是

表格1

表2

聽起來好像not exists 您沒有提供足夠的信息,但是想法是:

set @duedate = ?;  -- whatever your logic is for this

select t1.*
from table1 t1
where not exists (select 1
                  from table2 t2
                  where t2.id = t1.id and t2.date > @duedate
                 );

編輯:

根據您的評論,我推測您想要:

select t1.*
from table1 t1
where not exists (select 1
                  from table2 t2
                  where t2.id = t1.id and
                        (day(curdate()) > 10 and
                         t.2 > curdate() + interval (10 - day(curdate)) day
                        ) or
                        (day(curdate()) > 10 and
                         t.2 > curdate() + interval (10 - day(curdate)) day - interval 1 month
                        )
                 );

請注意,這可能無濟於事。 那遲付款呢? 這會將先前的逾期付款視為未逾期。

如果這是一個問題,我建議您再問一個問題。 將樣本數據和所需結果放入問題的文本表中。 清楚地說明所需的邏輯,任何示例查詢都將有所幫助。

您正在尋找的被稱為左聯接。 您可以通過按照以下方式進行操作來實現。

SELECT * FROM Table1 LEFT JOIN Table2 On Table1.Key=Table2.Key WHERE Table2.Key IS NULL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM