如何从Drupal Views中查看有效的mysql查询

时间:2012-09-29 19:40:23

标签: mysql drupal-7 drupal-views

我读了一些建议,但无法弄清楚如何生成由视图生成和显示的查询 - 在mysql中有效。在{}中有一些变量已关闭,而且我认为查询中有一些表在DB中不存在。我试图在这里提取一个非常复杂的查询。提前10倍!

SELECT field_data_field_punch_status.field_punch_status_value AS field_data_field_punch_status_field_punch_status_value, users.name AS users_name, users.uid AS uid_1, field_data_field_punch_start.field_punch_start_value AS field_data_field_punch_start_field_punch_start_value, field_data_field_team.field_team_tid AS field_data_field_team_field_team_tid, users.access AS users_access, MIN(users.uid) AS uid, 'user' AS field_data_field_punch_status_user_entity_type, 'user' AS field_data_field_punch_start_user_entity_type, MIN(node_users.nid) AS node_users_nid, 'node' AS field_data_field_punch_end_node_entity_type, MAX(node_users__field_data_field_punch_end.field_punch_end_value) AS node_users__field_data_field_punch_end_field_punch_end_value, 'user' AS field_data_field_team_user_entity_type
FROM 
{users} users
LEFT JOIN {field_data_field_team} field_data_field_team ON users.uid = field_data_field_team.entity_id AND (field_data_field_team.entity_type = 'user' AND field_data_field_team.deleted = '0')
INNER JOIN {taxonomy_term_data} taxonomy_term_data_field_data_field_team ON field_data_field_team.field_team_tid = taxonomy_term_data_field_data_field_team.tid
LEFT JOIN {node} node_users ON users.uid = node_users.uid
INNER JOIN {users_roles} users_roles ON users.uid = users_roles.uid
LEFT JOIN {field_data_field_punch_status} field_data_field_punch_status ON users.uid = field_data_field_punch_status.entity_id AND (field_data_field_punch_status.entity_type = 'user' AND field_data_field_punch_status.deleted = '0')
LEFT JOIN {field_data_field_punch_start} field_data_field_punch_start ON users.uid = field_data_field_punch_start.entity_id AND (field_data_field_punch_start.entity_type = 'user' AND field_data_field_punch_start.deleted = '0')
LEFT JOIN {field_data_field_punch_end} node_users__field_data_field_punch_end ON node_users.nid = node_users__field_data_field_punch_end.entity_id AND (node_users__field_data_field_punch_end.entity_type = 'node' AND node_users__field_data_field_punch_end.deleted = '0')
WHERE (( (field_data_field_team.field_team_tid IN('0', '10', '11', '22', '12', '2', '21', '3', '13', '4', '14', '5', '15', '6', '16', '7', '17', '18', '20', '19') ) AND (users_roles.rid IN  ('4', '5')) ))
GROUP BY field_data_field_punch_status_field_punch_status_value, users_name, uid_1, field_data_field_punch_start_field_punch_start_value, field_data_field_team_field_team_tid, users_access
ORDER BY field_data_field_punch_start_field_punch_start_value DESC, users_access DESC

1 个答案:

答案 0 :(得分:3)

您在花括号之间看到的内容(例如{field_data_field_team})是数据库表的名称。它们显示在大括号之间,因为执行SQL查询的代码会替换大括号之间的内容以及为数据库表设置的前缀。

假设您的Drupal安装使用drupal7_作为前缀;引用为{field_data_field_team}的表的名称为drupal7_field_data_field_team。