SQL Anywhere错误-对“id”的函数或列引用也必须出现在GROUP BY中
我有两张桌子: 测试表: 行: 测试2表: 行: 我需要得到这个结果:SQL Anywhere错误-对“id”的函数或列引用也必须出现在GROUP BY中,sql,sqlanywhere,Sql,Sqlanywhere,我有两张桌子: 测试表: 行: 测试2表: 行: 我需要得到这个结果: BMW 23 2200 BMW 22 2050 我的SQL: SELECT * FROM test, test_2 WHERE test_2.ad_id=test.id GROUP BY user_id ORDER BY test_2.price DESC 但我总是会犯这样的错误: 无法执行语句。 对“id”的函数或列引用也必须出现在GROUP BY中 SQLCODE=-149,ODBC 3状态=42000 第1行第1
BMW 23 2200
BMW 22 2050
我的SQL:
SELECT * FROM test, test_2 WHERE test_2.ad_id=test.id GROUP BY user_id ORDER BY test_2.price DESC
但我总是会犯这样的错误:
无法执行语句。
对“id”的函数或列引用也必须出现在GROUP BY中
SQLCODE=-149,ODBC 3状态=42000
第1行第1列
我在任何地方都使用SQL。感谢您的帮助。除了聚合函数外,group by中的所有列都应位于select子句中
SELECT test.name, test_2.user_id, max(test_2.price)
FROM test, test_2
WHERE test_2.ad_id=test.id
GROUP BY test.name, test_2.user_id
ORDER BY test_2.price DESC
然后我也得到了宝马23 2000。我需要1个用户=1行
id ad_id user_id price
----------- ----------- ----------- -----------
1 1 23 2000
2 1 23 2200
3 1 22 2050
BMW 23 2200
BMW 22 2050
SELECT * FROM test, test_2 WHERE test_2.ad_id=test.id GROUP BY user_id ORDER BY test_2.price DESC
SELECT test.name, test_2.user_id, max(test_2.price)
FROM test, test_2
WHERE test_2.ad_id=test.id
GROUP BY test.name, test_2.user_id
ORDER BY test_2.price DESC