有一个sql语句,分别在mybatis中执行和在mysql中执行结果不一致.

sql语句:

select 
ifnull(sum(AMOUNT),0) as "totalTxnAmount", 
sum(amount)as "lastDayTxnAmount",
(select group_concat(_ids) from (SELECT @ids as _ids, ( SELECT @ids := GROUP_CONCAT(agent_id) FROM CIF_AGENT_RELATION WHERE FIND_IN_SET(parent_id, @ids)>0 ) as cids FROM CIF_AGENT_RELATION a, (SELECT @ids:=10) b WHERE @ids IS NOT NULL ) t) aa 

from abiz_account_deal aa where BIZ_TYPE = 1 and DEAL_TYPE = 1

mybatis:

<==    Columns: totalTxnAmount, lastDayTxnAmount, aa
<==        Row: 11950143, 0, 10,11,4,9,70,71

mysql:

totalTxnAmount|lastDayTxnAmount|aa                                                                                                                                                                                       |
--------------+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      11950143|               0|10,11,17,16,25,37,39,54,58,75,79,11,92,4,4,14,15,18,19,24,24,26,27,27,40,41,42,41,50,50,55,59,66,66,76,80,81,81,27,9,43,44,44,60,61,61,60,63,63,67,67,72,72,77,77,84,84,85,85,70,70,71,71|

发现是因为使用了@ids := 和递归查询导致.

优化后:

正确结果:    10,11,17,16,25,37,39,54,58,75,79,11,92,4,4,14,15,18,19,24,24,26,27,27,40,41,42,41,50,50,55,59,66,66,76,80,81,81,27,9,43,44,44,60,61,61,60,63,63,67,67,72,72,77,77,84,84,85,85,70,70,71,71
mybatis结果:10,11,17,16,25,37,39,54,               4,4,14,15,18,19,24,2                                                       ,9,43,44,44,60,61,61,                                      ,70,70,71,71

文章作者: 刘同学
本文链接:
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 刘同学的小站
数据库 oracle Mysql
喜欢就支持一下吧