假设我有这个表:named = the_table ,其结构是:
PostgreSQL:
create table the_table (col3 SERIAL, col2 varchar, col1 varchar, PRIMARY KEY(col3));
Run Code Online (Sandbox Code Playgroud)
MySQL:
create table the_table ( col3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, col2 varchar(20), col1 varchar(20) )
Run Code Online (Sandbox Code Playgroud)
然后我插入表格:
INSERT INTO the_table (col2,col1) VALUES
('x','a'),
('x','b'),
('y','c'),
('y','d'),
('z','e'),
('z','f');
Run Code Online (Sandbox Code Playgroud)
现在表格如下所示:
col3 | col2 | col1
------+------+------
1 | x | a
2 | x | b
3 | y | c
4 | y | d
5 | z | e
6 | z …Run Code Online (Sandbox Code Playgroud) 我在 MYSQL 5.7 上收到此请求的错误。如何解决这个错误?
#1055 - SELECT 列表的表达式 #3 不在 GROUP BY 子句中,并且包含非聚合列“test.c.customers_group_id”,该列在功能上不依赖于 GROUP BY 子句中的列;这与 sql_mode=only_full_group_by 不兼容
select SQL_CALC_FOUND_ROWS c.customers_firstname,
c.customers_lastname,
c.customers_group_id,
sum(op.products_quantity * op.final_price) as ordersum
from customers c,
orders_products op,
orders o
where c.customers_id = o.customers_id
and o.orders_id = op.orders_id
group by c.customers_firstname,
c.customers_lastname
order by ordersum DESC
Run Code Online (Sandbox Code Playgroud)