我有两个表,(1)
表客户端和(2)
表客户端操作。
这是我的样本表:
表客户端:
id_clients | name | id_user_created | id_user_owner
1 alfa 4 0
2 beta 4 0
3 charlie 5 0
表客户端操作:
id_clients_action | date_action | id_clients | id_user_created | id_user_owner
1 2015-09-04 17:09:37 1 4 0
2 2015-09-05 18:19:07 1 4 0
然后,在表单中,我有两个输入参数,从日期到日期。
这些是我的条件:
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
下一个条件:
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 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'
)
答案 0 :(得分:0)
Enter a keyword or phrase into the box below to see if it's trending.
<br>
<input placeholder="***input***"></input>
<iframe src="http://www.google.com/trends/fetchComponent?hl=en-US&q=***INPUT***&cid=TIMESERIES_GRAPH_0&export=5&w=500&h=300"></iframe>