我试图输出如下:
Int
使用
Average score
10
col1 col2 score
...
当我只选择AVG(分数)或*而不是两者时,这是有效的。有没有办法在不重复代码的情况下做到这一点?
这是我尝试时遇到的错误:
SELECT AVG(Score), *
FROM (
SUM(...) AS col1
SUM(...) AS col2
SUM(...) AS Score
) AS T1
答案 0 :(得分:0)
您不能将*
与其他列一起使用。你可以这样做:
SELECT * FROM...
或
SELECT col1, col2, col3... FROM...
但不是
SELECT col1, col2, col3, * FROM...
示例:
mysql> SELECT id FROM users LIMIT 5;
+----+
| id |
+----+
| 18 |
| 22 |
| 23 |
| 26 |
| 27 |
+----+
5 rows in set (0.00 sec)
mysql> SELECT id, * FROM users LIMIT 5;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM users LIMIT 5' at line 1
答案 1 :(得分:0)