' SUM()'在输出映射中使用SQL(Grails)

时间:2017-05-06 12:29:35

标签: mysql grails

在我的MySQL Workbench中,以下查询完美运行:

SELECT card.number, SUM(qty)
FROM card_set, card, user_card
WHERE card_set.id = card.card_set_id
AND user_card.card_id = card.id
AND card_set.id = 1
GROUP BY card.number ORDER BY card.number;

但是,在我的Grails控制器中,我有以下内容:

SELECT card.number, SUM(qty)" +
"FROM card_set, card, user_card\n" +
"WHERE card_set.id = card.card_set_id\n" +
"AND user_card.card_id = card.id\n" +
"AND card_set.id = 1\n" +
"GROUP BY card.number ORDER BY card.number;"

输出是这样的:

[['number':1, 'SUM(qty)':2], ['number':2, 'SUM(qty)':3], ['number':3, 
'SUM(qty)':0], ['number':4, 'SUM(qty)':0], ['number':5, 'SUM(qty)':-2], 
['number':6, 'SUM(qty)':0], ['number':7, 'SUM(qty)':2], ['number':8, 
'SUM(qty)':2], ['number':9, 'SUM(qty)':0], ['number':10, 'SUM(qty)':0], 
['number':11, 'SUM(qty)':1], ['number':12, 'SUM(qty)':0], ['number':13, 
'SUM(qty)':1], ['number':14, 'SUM(qty)':1], ['number':15, 'SUM(qty)':2], 
['number':16, 'SUM(qty)':-1], ['number':17, 'SUM(qty)':0], ['number':18, 
'SUM(qty)':0], ['number':19, 'SUM(qty)':1], ['number':20, 'SUM(qty)':0]]

为什么Grails会推出文本" SUM(qty)"到地图列表?我如何格式化它呢?

0 个答案:

没有答案