小编tir*_*rso的帖子

mysql左外连接

我有两张桌子:

  1. employee 字段employee_id,名字,中间名,姓氏
  2. timecard 使用字段employee_id,time-in,time-out,tc_date_transaction

我想选择具有相同employee_id的所有员工记录,其中timecard和date与当前日期相同.如果没有与当前日期相等的记录,那么即使没有time-in,timeout和tc_date_transaction,也会返回员工的记录.

我有这样的查询

SELECT * 
  FROM employee LEFT OUTER JOIN timecard 
       ON employee.employee_id = timecard.employee_id
 WHERE tc_date_transaction = "17/06/2010";
Run Code Online (Sandbox Code Playgroud)

结果应该是这样的:

employee_id | firstname | middlename | lastname | time-in | time-out | tc_date_transaction
------------------------------------------------------------------------------------------
     1      | john      | t          | cruz     | 08:00   | 05:00    | 17/06/2010     
     2      | mary      | j          | von      | null    | null     | null

mysql

10
推荐指数
1
解决办法
5万
查看次数

标签 统计

mysql ×1