我想使用下表提取最近两个月的数据: 我达到了这个目标:
select * from requests r
INNER JOIN request_status rs
ON r.id = rs.request_id
where r.customer_id = <some-customer-id>
AND r.created_time_stamp
BETWEEN '2016-011-01 00:00:00.000000'
AND '2017-01-05 00:00:00.000000' limit 10
问题是我不确定如何在上述查询的结果集上放置另一个内连接。我必须实现的是在上面的查询的结果集上执行内部联接并从该结果集中提取一些数据。任何帮助如何去做?
+-----+--------------------+
| id | created_time_stamp |
+-----+--------------------+
| 123 | 12:23:00 |
+-----+--------------------+
+----+------------+-------------+
| id | request_id | customer_id |
+----+------------+-------------+
| 12 | 123 | 3453 |
+----+------------+-------------+
+----+-------------+------------+
| id | customer_id | process_id |
+----+-------------+------------+
| 12 | 3453 | 23 |
+----+-------------+------------+
编辑1:
考虑以下表格,并在冒号后列出字段:
注意:push_status中的request_id是push_request的id的外键
我想在查询中实现的目标:
我期待的输出结果:包含整行push_requests,push_status和附加列的最终结果集,其中显示了is_inactive值为0的订阅者数量。
答案 0 :(得分:1)
我不知道你为什么不能在你的查询中添加另一个连接条件,加入request_process
表:
SELECT *
FROM requests r
INNER JOIN request_status rs
ON r.id = rs.request_id
INNER JOIN request_process rp
ON rs.customer_id = rp.customer_id
WHERE r.customer_id = <some-customer-id> AND
r.created_time_stamp BETWEEN '2016-01-01 00:00:00.000000' AND
'2017-01-05 00:00:00.000000'
LIMIT 10
请注意,我更正了时间戳'2016-01-01 00:00:00.000000'
中的拼写错误。