开发者

Can't use aggregate functions in drupal 7 views module

开发者 https://www.devze.com 2023-03-26 17:20 出处:网络
I\'m trying to calculate the sum of a list of prices (decimal field) with the views module. And it just doesn\'t want to work... What am I doing wrong or.. is it just a bug ?

I'm trying to calculate the sum of a list of prices (decimal field) with the views module. And it just doesn't want to work... What am I doing wrong or.. is it just a bug ?

Software used

  • drupal v7.7
  • cTools v7.x-1.0-rc1

View configuration 1

  • Use aggregation: Yes
  • Fields : Title, sumPricesField
  • Aggregation settings of sumPricesField : Aggregation type = SUM
  • Group column = Value

Result 1

sumPricesField remains blank in output, the only aggregation type that gives a value is COUNT

View configuration 2

  • Use aggregation: Yes
  • Fields : Title, sumPricesField
  • Aggregation settings of sumPricesField : Aggregation type = SUM
  • Group column = Value
  • Group columns (additional) = Entity ID result in MySQL error

Result 2

SQL error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in 
your SQL syntax; check the manual that corresponds to your MySQL server version 
for the right syntax to use near 'id) AS field_data_field_algembeo_entityid FROM
drupal_node node LEFT开发者_Go百科 JOIN drupa' at line 1

Generated Query:

SELECT 
  node.title AS node_title, 
  node.nid AS nid, 
  node.created AS node_created, 
  MIN(node.nid) AS nid_1, 
  'node' AS field_data_field_bedrag_node_entity_type,
  SUM(field_data_field_bedrag.field_bedrag_value) AS field_data_field_bedrag_field_bedrag_value, 
  SUM(field_data_field_bedrag.entity id) AS field_data_field_bedrag_entityid
FROM 
  {node} node
  LEFT JOIN {field_data_field_bedrag} field_data_field_bedrag ON node.nid = field_data_field_bedrag.entity_id AND (field_data_field_bedrag.entity_type = node AND field_data_field_bedrag.deleted = 0)
WHERE 
  (( (node.status = '1') ))
GROUP BY 
  node_title, nid, node_created
ORDER BY 
  node_created DESC
LIMIT 
  10 OFFSET 0


I had the same problem with SUMming up some float fields. I found this patch which solved the issue for me http://drupal.org/node/1194900 The mentioned jQuery error occurs on my site too after the patch but at least the aggregation works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号