我试图在我的roundup安装中更改日期搜索行为,但SQL并不是我的强项。这是现有的查询:
select _issue.id,_issue._activity,(_issue._activity is not NULL),
_priority3._order,(_priority3._order is not NULL) from _issue
LEFT OUTER JOIN _priority as _priority3
on _issue._priority=_priority3.id
where _issue._activity >= '2015-01-16 08:00:00.000' and
_issue._activity <= '2015-01-17 07:59:59.000' and
_issue.__retired__=0
order by (_priority3._order is not NULL),_priority3._order,
(_issue._activity is not NULL),_issue._activity,_issue.id
以下是包含有趣字段的表格:
table: _issue
fields: id (integer)
_activity (timestamp)
_priority (integer)
table: _priority (alias priority3)
fields: id (integer)
order (real)
我需要使用的表格:
table: issue_messages
fields: linkid (integer, id of message)
nodeid (integer, id of issue)
table: _msg
fields: id (integer)
_activity (timestamp)
我想要的是包含任何活动的问题列表,这意味着检查邮件活动日期,而不是问题活动日期(仅反映上一个活动)。
答案 0 :(得分:1)
听起来这就像你所追求的那样:
SELECT
--
-- The fields you want to return
--
FROM _issue, issue_messages, _msg, _priority AS _priority3 -- I emulated your alias
WHERE
_issue.id = issue_messages.nodeid AND
issue_messages.linkid = _msg.id AND
_issue._priority = _priority3.id AND
_msg._activity BETWEEN '2015-01-16 08:00:00.000' AND '2015-01-17 07:59:59.000'
--
-- And maybe other filtering conditions you need
--
ORDER BY
--
-- The fields by which you want to order
--