我是否有从两个MySQL查询创建Drupal视图。我想创建一个事件视图,一个MySQL查询用于引发已启动但尚未完成的事件,另一个查询是调出事件还没有开始,总共显示3个项目。
以下是我想要创建视图的两个SQL查询:
SELECT f.delta AS field_data_field_session_start_date_delta
, f.entity_id AS date_id_date_filter
, f.delta AS date_delta_date_filter
, n.title AS node_title
, n.nid AS nid
, n.language AS node_language
, f.field_session_start_date_value AS field_data_field_session_start_date_field_session_start_date
, f.field_session_start_date_value2 AS field_data_field_session_start_date_field_session_start_date2
, 'node' AS field_data_field_session_start_date_node_entity_type
FROM `node` n
JOIN `field_data_field_session_start_date` f
ON f.entity_id = n.nid
AND f.entity_type = 'node'
AND f.deleted = '0'
AND f.field_session_start_date_value >= NOW()
WHERE n.status = '1'
ORDER
BY f.field_session_start_date_value ASC
LIMIT 3 OFFSET 0
SELECT f.delta AS field_data_field_session_start_date_delta
, f.entity_id AS date_id_date_filter
, f.delta AS date_delta_date_filter
, n.title AS node_title
, n.nid AS nid
, n.language AS node_language
, f.field_session_start_date_value AS field_data_field_session_start_date_field_session_start_date
, f.field_session_start_date_value2 AS field_data_field_session_start_date_field_session_start_date2
, 'node' AS field_data_field_session_start_date_node_entity_type
FROM `node` n
JOIN `field_data_field_session_start_date` f
ON f.entity_id = n.nid
AND f.entity_type = 'node'
AND f.deleted = '0'
AND f.field_session_start_date_value <= NOW()
AND f.field_session_start_date_value2 > NOW()
WHERE n.status = '1'
ORDER
BY f.field_session_start_date_value ASC
LIMIT 3 OFFSET 0
答案 0 :(得分:1)
我假设您知道如何从原始sql创建Drupal视图 - 即只是其中一个查询。
您可以使用UNION命令创建一个返回两个查询结果的查询(在您的情况下,将两个查询都括在括号中以确保ORDER BY和LIMIT与内部查询相关联):
(SELECT f.delta AS field_data_field_session_start_date_delta
, f.entity_id AS date_id_date_filter
, f.delta AS date_delta_date_filter
, n.title AS node_title
, n.nid AS nid
, n.language AS node_language
, f.field_session_start_date_value AS field_data_field_session_start_date_field_session_start_date
, f.field_session_start_date_value2 AS field_data_field_session_start_date_field_session_start_date2
, 'node' AS field_data_field_session_start_date_node_entity_type
FROM `node` n
JOIN `field_data_field_session_start_date` f
ON f.entity_id = n.nid
AND f.entity_type = 'node'
AND f.deleted = '0'
AND f.field_session_start_date_value >= NOW()
WHERE n.status = '1'
ORDER
BY f.field_session_start_date_value ASC
LIMIT 3 OFFSET 0)
UNION
(SELECT f.delta AS field_data_field_session_start_date_delta
, f.entity_id AS date_id_date_filter
, f.delta AS date_delta_date_filter
, n.title AS node_title
, n.nid AS nid
, n.language AS node_language
, f.field_session_start_date_value AS field_data_field_session_start_date_field_session_start_date
, f.field_session_start_date_value2 AS field_data_field_session_start_date_field_session_start_date2
, 'node' AS field_data_field_session_start_date_node_entity_type
FROM `node` n
JOIN `field_data_field_session_start_date` f
ON f.entity_id = n.nid
AND f.entity_type = 'node'
AND f.deleted = '0'
AND f.field_session_start_date_value <= NOW()
AND f.field_session_start_date_value2 > NOW()
WHERE n.status = '1'
ORDER
BY f.field_session_start_date_value ASC
LIMIT 3 OFFSET 0)