我正面临一种情况,需要帮助。我有两个表:mysql LEFT JOIN select results with limited results
用户:
user_id
,fname
,lname
,email
。
user_timesheet:
time_id
,user_id
,month
,state
,date
。
用户对时间与状态添加到user_time
表=“不”,并在月底他们提交时间,这改变状态=“是”假设一个月JUNE 我想编写一个查询,它将使所有没有添加时间的用户和已添加时间但尚未提交给JUNE的用户。
这是我的查询。
SELECT user_timesheet.time_id, user_timesheet.user_id,
user_timesheet.month, user_timesheet.`state`,
`user`.user_id, `user`.fname, `user`.lname,
`user`.email
FROM user LEFT JOIN
user_timesheet ON user.user_id=user_timesheet.user_id
WHERE (
user_timesheet.state = 'no' OR
user_timesheet.state IS NULL)
AND (
user_timesheet.month = 'june' OR
user_timesheet.month IS NULL)
GROUP BY user.user_id
结果带来谁已经在6月新增时间所有用户,而且已经提交了它,也从来没有谁补时到系统的用户,因为他们加入。但是,它并没有为上个月增加时间或提交时间的用户提供服务,但在六月份没有增加时间。
非常感谢你。请问如果我可能会问,这个<>在语句 –
@ user1451414 <>中意味着什么意味着在标准sql中不等于'。欢迎您:-) –
好,那么!=和<> –