2

我正在使用views_query_alter更改视图查询。在我的查询中,我想要类似的条件 DATE_FORMAT(FROM_UNIXTIME(field_data_field_hiddeneventdate.field_hiddeneventdate_value), '%m') = '06'

但是当我尝试

    $condition = array('field' =>   "DATE_FORMAT(FROM_UNIXTIME(field_data_field_hiddeneventdate.field_hiddeneventdate_value),   '%m')",
'value' => date('%Y-%m'), //$view->exposed_raw_input['title'],
'operator' => '>=',
);

它生成查询:

SELECT node.title AS node_title, node.nid AS nid, field_data_field_hiddeneventdate.field_hiddeneventdate_value AS node_changed
FROM 
{node} node
LEFT JOIN {field_data_field_hiddeneventdate} field_data_field_hiddeneventdate ON node.nid = field_data_field_hiddeneventdate.entity_id AND (field_data_field_hiddeneventdate.entity_type = node AND field_data_field_hiddeneventdate.deleted = 0)
WHERE (( (node.status = '1') AND (node.type IN  ('events_meeting')) )AND( (DATE_FORMATFROM_UNIXTIMEfield_data_field_hiddeneventdate.field_hiddeneventdate_valuem >= '%2013-%06') ))
LIMIT 10 OFFSET 0.

但我想要 :

SELECT node.title AS node_title, node.nid AS nid, field_data_field_hiddeneventdate.field_hiddeneventdate_value AS node_changed,
DATE_FORMAT(FROM_UNIXTIME(field_data_field_hiddeneventdate.field_hiddeneventdate_value), '%d-%m-%Y') AS dt
FROM node node
LEFT JOIN field_data_field_hiddeneventdate field_data_field_hiddeneventdate 
ON 
node.nid = field_data_field_hiddeneventdate.entity_id 
AND 
(field_data_field_hiddeneventdate.entity_type = 'node' 
AND field_data_field_hiddeneventdate.deleted = 0)
WHERE (( (node.status = '1') AND (node.type IN  ('events_meeting')) )
AND(           DATE_FORMAT(FROM_UNIXTIME(field_data_field_hiddeneventdate.field_hiddeneventdate_value), '%m') = '06' 
    )
)
LIMIT 10 OFFSET 0;

谁能帮我。

4

1 回答 1

0

如果您想更改视图的查询,为什么不直接使用视图并执行 db_select。直接 db 查询比 Drupal 中的视图更快。

于 2013-09-13T08:09:00.090 回答