我看到了几个回答可以解决您的查询的答案,但是我的查询中有GROUP BY CONCAT
,而且不确定如何解决。
cur.execute('''
SELECT user_id, symbol FROM first_sweep
WHERE date_time BETWEEN %s AND %s AND action = 'buy'
GROUP BY CONCAT(user_id, "-",symbol)
''', (min_rng, max_rng,))
fs = cur.fetchall()
我得到的全部错误是:
(1055, "Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'stockpicker.first_sweep.user_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by")
我正在使用Ubuntu 18.04,MySql 5.7和Python 2.7
答案 0 :(得分:1)
这有效:
SELECT
CONCAT(user_id, '-', symbol) as usym,
MAX(user_id) AS user_id,
MAX(symbol) AS symbol
FROM first_sweep
WHERE date_time BETWEEN %s AND %s AND action = 'buy'
GROUP BY usym