简体   繁体   English

如何从一个表中检索所有记录并与当月记录一起

[英]how to retrieve all records from one table in join with current month records

I have 2 tables in my Sqlite database one is USER and other is PAYMENTS 我的Sqlite数据库中有2个表,一个是USER,另一个是PAYMENTS

USERS: 用户:

ID  Name
"1" "shan"  
"2" "Abc"   
"3" "Def"   
"4" "Whi"

PAYMENTS: 付款方式:

ID  UserID  PayDate         Amount 
"1" "1" "2013-10-27"    "700"
"2" "1" "2013-11-12"    "700"
"3" "2" "2013-09-12"    "800"

How to retrieve all users and those user who paid the amount of the current month. 如何检索所有用户以及已支付当月金额的那些用户。 i also want all users who didn't paid yet. 我还希望所有尚未付款的用户。

Try somthing like this: 尝试这样的事情:

SELECT Users.Name 
FROM Users
LEFT JOIN Payments
  ON Users.ID = Payments.UserID
WHERE Payments.PayDate = <date you are looking for>

You can also use WHERE PayDate BETWEEN 'date1' and 'date2' This should return all users and payment will be NULL if there is no payment record. 您还可以在“ date1”和“ date2”之间使用WHERE PayDate。这应该返回所有用户,如果没有付款记录,则付款将为NULL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM