MySQL 错误 "Expression #1 of ORDER BY clause is not in GROUP BY clause"
MySQL error "Expression #1 of ORDER BY clause is not in GROUP BY clause"
我正在尝试从 table 中获取记录总数并使用以下 MySQL 查询:
SELECT COUNT(*) AS cnt FROM `info` WHERE 1 GROUP BY FROM_UNIXTIME(signup_date, '%Y-%m-%d') ORDER BY signup_date DESC
但它会导致以下错误:
SQL Error(1055): Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'rentown.info.signup_date'
which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by.[SELECT COUNT()
AS cnt FROM info
WHERE 1 GROUP BY FROM_UNIXTIME(signup_date,
'%Y-%m-%d') ORDER BY signup_date DESC]
这是我的 table 格式:
+ Options
id email signup_date ip city_name firstname address state lastname city zipcode phonenumber current_url creditscore
4 kfct@yahoo.com 1388525440 108.200.78.136 Philadelphia, PA Kathy 1915 Apex Ave #1/4 California Yeung Los Angeles 90039 310 890 3338 NULL NULL
10 mlh@gmail.com 1388884727 98.199.141.66 Dickinson, TX Mackenzie 102 strand Texas Helms Galveston 77550 409 599 8024 NULL NULL
11 mjma@yahoo.com 1388889053 99.190.210.155 Grand Prairie, TX samathiis 1701 towne crossing blvd #731 Texas ashley mansfield 76063 817 210 NULL NULL
该错误消息是不言自明的。您只能按出现在 GROUP BY
子句或聚合中的列进行排序。为了快速修复,只需按分组时使用的相同术语排序。
SELECT COUNT(*) AS cnt
FROM `info`
GROUP BY FROM_UNIXTIME(signup_date, '%Y-%m-%d')
ORDER BY FROM_UNIXTIME(signup_date, '%Y-%m-%d') DESC
对于记录总数,这应该足够了:
SELECT COUNT (*) AS cnt
FROM 'info'
ORDER BY signup_date DESC
我正在尝试从 table 中获取记录总数并使用以下 MySQL 查询:
SELECT COUNT(*) AS cnt FROM `info` WHERE 1 GROUP BY FROM_UNIXTIME(signup_date, '%Y-%m-%d') ORDER BY signup_date DESC
但它会导致以下错误:
SQL Error(1055): Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'rentown.info.signup_date' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.[SELECT COUNT() AS cnt FROM
info
WHERE 1 GROUP BY FROM_UNIXTIME(signup_date, '%Y-%m-%d') ORDER BY signup_date DESC]
这是我的 table 格式:
+ Options
id email signup_date ip city_name firstname address state lastname city zipcode phonenumber current_url creditscore
4 kfct@yahoo.com 1388525440 108.200.78.136 Philadelphia, PA Kathy 1915 Apex Ave #1/4 California Yeung Los Angeles 90039 310 890 3338 NULL NULL
10 mlh@gmail.com 1388884727 98.199.141.66 Dickinson, TX Mackenzie 102 strand Texas Helms Galveston 77550 409 599 8024 NULL NULL
11 mjma@yahoo.com 1388889053 99.190.210.155 Grand Prairie, TX samathiis 1701 towne crossing blvd #731 Texas ashley mansfield 76063 817 210 NULL NULL
该错误消息是不言自明的。您只能按出现在 GROUP BY
子句或聚合中的列进行排序。为了快速修复,只需按分组时使用的相同术语排序。
SELECT COUNT(*) AS cnt
FROM `info`
GROUP BY FROM_UNIXTIME(signup_date, '%Y-%m-%d')
ORDER BY FROM_UNIXTIME(signup_date, '%Y-%m-%d') DESC
对于记录总数,这应该足够了:
SELECT COUNT (*) AS cnt
FROM 'info'
ORDER BY signup_date DESC