我想找一个没有专辑的乐队。
- 这是我的表结构**:
CREATE TABLE bands (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE albums (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
release_year INT,
band_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (band_id) REFERENCES bands(id)
);
- 这是查询:**
SELECT bands.name AS 'Band Name' ,count(albums.band_id) AS ALBUMS FROM bands
JOIN albums ON bands.id = albums.band_id
GROUP BY albums.band_id
HAVING count(albums.band_id) = 0;
- 错误:**
Error Code: 1055. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'record_company.bands.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
1条答案
按热度按时间i86rm4rw1#
试试这个
由于SELECT表达式中有
bands.name
,且该表达式带有聚合函数COUNT,因此需要GROUP BYbands.name
。如果成功了告诉我?