I believe many students encounter the problem of invalid prompt identifier when using group by. Don’t worry, let’s summarize the common solutions to this problem:
Example: take the information of the youngest employee in each department
my SQL statement is as follows:
select name,min(age),(select deptname from dept d where d.deptid=uif.deptid)deptname from userinfo uif group by name,deptname
When you click execute, the system prompts:
ORA-00904:"deptname":Identifier is invalid
Error reason: the field after group by cannot be an alias (if you want to use an alias, you need to nest it at one level)
Solution 1:
--goup by The department name (alias: deptname ) is directly used in the deptid field of the employee information table
select name,min(age),(select deptname from dept d where d.deptid=uif.deptid)deptname from userinfo uif group by uif.name,uif.deptid
Solution 2:
--Grouping after one level of nesting
select us.name,min(us.age),us.deptname from (select name,age,(select deptname from dept d where d.deptid=uif.deptid)deptname from userinfo uif)us
group by us.name,us.deptname
How about this time?If you have any questions, please leave a message to study together~
Read More:
- [MySQL] The principle of group by aggregation function and the reason for aggregation limitation SELECT list is not in GROUP BY clause and contains nonaggregated column
- How to Solve MySQL version 5.7+ Group by group error
- MYSQL gruop by Error: this is incompatible with sql_mode=only_full_group_by
- SQL Server Group sort de duplication row_ number() over ( PARTITION BY t1.col_ 2 ORDER BY 1 )
- [Solved] MYSQL 5.7 gruop by eRROR: this is incompatible with sql_mode=only_full_group_by
- Mysql :error 1111. Invalid use of group function
- [Solved] ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate
- [Solved] Sequelize DatabaseError: ER_WRONG_FIELD_WITH_GROUP: Expression #2 of SELECT list is not in GROUP
- [Solved] MySQL Error: ERROR 1055 (42000)sql_mode=only_full_group_by
- [Solved] MySQL Error: “Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- postgresql-Database query problem-ERROR: column “t.domainid“ must appear in the GROUP BY clause or be used in an a
- [Solved] MYSQL Start Project Error: this is incompatible with sql_mode=only_full_group_by
- The attributes of Oracle batch modification sequence (such as cache)_size, increment_(by et al.)
- MySQL OrderBy Error: Expression #1 of ORDER BY
- [Solved]ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
- How to Solve mysql [Err] 1067-Invalid default value for
- [Solved] MySQL5.6.44 [Err] 1067 – Invalid default value for create_date settlement programme
- Mysql ERROR 1067: Invalid default value for ‘date’ [How to Solve]
- SQL server converts multiple lines into one line, separated by characters
- [Solved] MySQL Error: Client does not support authentication protocol requested by server