我想弄清楚这一点,但我一直收到这个错误。我知道它与SELECT和HAVING子句中的子查询有关,但我不知道如何修复它们。任何帮助将不胜感激。
部门表:https://gyazo.com/f9d782abd428acc7ec2e7d5d59befad7
员工表:https://gyazo.com/b2d7d792c0933b13d6fdd7166fffb8a6
预期输出:https://gyazo.com/41f6a5626a5827acbe76e3c41287742d
编辑:我想出了另一种语法!谢谢你的帮助!
CURSOR c_emp (p_total_emp NUMBER) IS
SELECT department.DEPARTMENT_NAME
, MAX(employee.HIRE_DATE)
, (SELECT COUNT(EMPLOYEE_ID)
FROM employee
HAVING HIRE_DATE = MAX(HIRE_DATE))
, ROUND(MAX(employee.SALARY))
, ROUND(MAX(employee.SALARY) * 0.68)
, (SELECT COUNT(EMPLOYEE_ID)
FROM employee
HAVING SALARY > ROUND(MAX(employee.SALARY) * 0.68))
FROM employee
INNER JOIN department
ON employee.DEPARTMENT_ID = department.DEPARTMENT_ID
GROUP BY 1
HAVING (SELECT COUNT(EMPLOYEE_ID)
FROM employee
HAVING SALARY > ROUND(MAX(employee.SALARY) * 0.68)) > p_total_emp
ORDER BY DEPARTMENT_NAME ASC
;
示例:
答案 0 :(得分:1)
希望你到目前为止度过了愉快的一周。 :)
只是抬头查询,您遇到错误,因为您不能GROUP BY 1.您需要GROUP BY列,而不是聚合。 (例如,department.DEPARTMENT_NAME)如下: -
@Component
public class PayloadDeserializer {
private final MyMapper mapper;
@Autowired
public PayloadDeserializer(MyMapper mapper) {
this.mapper = mapper;
}
}
@Configuration
public class TopLevelConfig {
@Bean
public MyMapper myMapper(PayloadDeserializer payloadDeserializer) {
MyMapper mapper = new MyMapper();
mapper.registerModule(metadataModule(payloadDeserializer));
return mapper;
}
@Bean
public MetadataModule metadataModule(PayloadDeserializer payloadDeserializer) {
return new MetadataModule(payloadDeserializer);
}
}
public class MetadataModule {
private final PayloadDeserializer payloadDeserializer;
public MetadataModule(PayloadDeserializer payloadDeserializer) {
this.payloadDeserializer = payloadDeserializer;
}
@Override
public void setupModule(final SetupContext setupContext) {
final SimpleDeserializers deserializers = new SimpleDeserializers();
deserializers.addDeserializer(Payload.class, payloadDeserializer);
setupContext.addDeserializers(deserializers);
}
}