Unknown column with only-full-group-by
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```
CREATE TABLE wa_data (
PK_WA_DATA INT PRIMARY KEY,
PK_PSNDOC INT,
ADDTYPE CHAR(1),
F_5 DECIMAL(10, 2)
);
INSERT INTO wa_data (PK_WA_DATA, PK_PSNDOC, ADDTYPE, F_5) VALUES
(1, 101, '0', 10.00),
(2, 101, '1', 15.00),
(3, 101, '1', 20.00),
(4, 102, '0', 30.00),
(5, 102, '1', 40.00),
(6, 103, '1', NULL);
SELECT
wa_data.PK_WA_DATA,
(
SELECT
CASE
wa_data.addtype
WHEN '0' THEN
0
ELSE
COALESCE(SUM(wadata.F_5), 0) * 1.00000000
END
FROM
wa_data wadata
WHERE
wadata.PK_PSNDOC = wa_data.PK_PSNDOC
) AS f_455
FROM
wa_data;
```
### 2. What did you expect to see? (Required)
success to run.
### 3. What did you see instead (Required)
```
mysql> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)
mysql> select (select case t.j when 0 then 0 else sum(j) end from t t1 where t1.i=t.i) as col from t;
Empty set (0.00 sec)
mysql> set sql_mode=default;
Query OK, 0 rows affected (0.00 sec)
mysql> select (select case t.j when 0 then 0 else sum(j) end from t t1 where t1.i=t.i) as col from t;
ERROR 1054 (42S22): Unknown column 't.i' in 'where clause'
```
### 4. What is your TiDB version? (Required)
```
+-----------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------+
| Release Version: v9.0.0-beta.1.pre-519-ge9916cf30b |
| Edition: Community |
| Git Commit Hash: e9916cf30bc99d1ccc831e550ebb64bbce9c6407 |
| Git Branch: HEAD |
| UTC Build Time: 2025-04-08 03:27:57 |
| GoVersion: go1.23.8 |
| Race Enabled: false |
| Check Table Before Drop: false |
| Store: tikv |
+-----------------------------------------------------------+
```
Contributor guide
Assessment
This issue has not been assessed yet.