I am using feed module to import form excel file, one of my field is a incremental number 1,2,3,4,5 ,..... ' , I get it as 'GUID' in feed importer. I want sort the result in views, I see the views get GUID as a string and sort it by string.anybody have idea how can I sort them as number ? I want views sort GUID as integer not string
I test this but it return me sql error,
The sql query of first(top) test :
SELECT node.title AS node_title, node.nid AS nid, feeds_item.guid AS feeds_item_guid, 'node' AS field_data_field_model_node_entity_type, 'node' AS field_data_field_price_node_entity_type
FROM
{node} node
LEFT JOIN {feeds_item} feeds_item ON node.nid = feeds_item.entity_id AND feeds_item.entity_type = 'node'
WHERE (( (node.status = '1') AND (node.type IN ('products')) ))
ORDER BY CAST(feeds_item_guid AS INTEGER) ASC
LIMIT 100 OFFSET 0
function mymodule_views_query_alter(&$view, &$query) {
if ($view->name == 'my_views') {
$query->orderby[0]['field']='CAST('.$query->orderby[0]["field"].' AS INTEGER)';
}
or I try
$query->fields['feeds_item_guid']['field']='CAST('.$query->fields['feeds_item_guid']['field'].' AS INTEGER)';
error of second try: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'feeds_item.CASTguidASINTEGER' in 'field list'