Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mysql中使用join查询日期_Mysql - Fatal编程技术网

在mysql中使用join查询日期

在mysql中使用join查询日期,mysql,Mysql,我有两个表,(1)表客户端和(2)表客户端操作。 这是我的示例表: 表客户端: 表1客户端操作: 然后,在一个表单中,我有两个输入参数,from date和to date。以下是我的条件: Condition-1 : -id_user_created = 4 -from date = 2015-09-01 00:00:00 -end date = 2015-09-03 00:00:00 我想要这样的结果: id_clients | name | date 1 al

我有两个表,
(1)
表客户端和
(2)
表客户端操作。
这是我的示例表:

表客户端:

表1客户端操作:

然后,在一个表单中,我有两个输入参数,from date和to date。
以下是我的条件:

Condition-1 : 
-id_user_created = 4
-from date = 2015-09-01 00:00:00
-end date = 2015-09-03 00:00:00
我想要这样的结果:

 id_clients | name | date 
     1        alfa   null
     2        beta   null
id_clients | name | date 
    1        alfa   2015-09-04 17:09:37
    1        alfa   2015-09-05 18:19:07
    2        beta   null
下一个条件:

Condition-2 : 
-id_user_created = 4
-from date = 2015-09-01 00:00:00
-end date = 2015-09-22 00:00:00
我想要这样的结果:

 id_clients | name | date 
     1        alfa   null
     2        beta   null
id_clients | name | date 
    1        alfa   2015-09-04 17:09:37
    1        alfa   2015-09-05 18:19:07
    2        beta   null
下面是我的查询,但我仍然有一个真实的日期,当我想从我的条件的结果。请给我一个真实的问题

select B.id_clients, B.id_user_created, B.name, A.date_action as  lastActionDate
from clients_action as A
right join clients as B on A.id_clients=B.id_clients
where 
B.id_clients in 
(
     select id_clients 
     from clients_action where 
     date_action between '2015-09-01 00:00:00' and '2015-09-03 00:00:00' and id_user_owner = '0'
)
or
B.id_clients in 
(
    select id_clients 
    from clients 
     where 
    id_user_created = '4' and id_user_owner = '0'
)

抱歉,id\u客户端\u操作是dinamic…:(对不起,id\u客户端\u操作是dinamic…:(
select distinct
a.id_clients,a.name,
case when b.id_clients_action=2 then b.date_action else null end as date
from clients a
left join clients_action b on a.id_user_created=b.id_user_created