0
Hello . I am trying to execute a certain Query on Oracle and I am getting the following error : "is not a GROUP BY expression". Below is the list of tables and query:
BILL
NRO_CONTA|COD_AGENCIA|NOME |SALDO |LIMITE|ENDERECO|DDD_FONE|
---------|-----------|----------|-------|------|--------|--------|
30001| 30|ANA TERESA| 1000| 500| | |
30002| 30|CAROLINA | 5500| 2500| | |
30003| 30|JOAQUIM | 800| 0| | |
ENFORCEMENT FUND
NRO_CONTA|DATA_APLIC |COD_FUNDO|NRO_COTAS |VLR_APLIC|
---------|-------------------|---------|----------|---------|
30007|2010-01-04 00:00:00| 1|999.430325| 1000|
45004|2010-01-04 00:00:00| 1|749.572744| 750|
30002|2010-01-04 00:00:00| 2|999.350422| 1000|
QUOTA FUND
COD_FUNDO|DATA_COTA |VALOR_COTA|
---------|-------------------|----------|
1|2010-01-01 00:00:00| 1|
2|2010-01-01 00:00:00| 1|
3|2010-01-01 00:00:00| 1|
QUERY
SELECT C.NRO_CONTA, C.NOME, C.SALDO ,
ROUND(SUM(FA.COTAS * FA.VALOR_COTA),2) AS SALDO_APLIC
FROM CONTA C
JOIN (
SELECT FA.NRO_CONTA , FA.COD_FUNDO, FA.NRO_COTAS AS COTAS , DC.VALOR_COTA AS VALOR_COTA
FROM FUNDOS_APLIC FA
JOIN (SELECT COD_FUNDO, MAX(DATA_COTA) AS DATA_COTA , VALOR_COTA FROM FUNDOS_COTA GROUP BY COD_FUNDO) DC ON FA.COD_FUNDO = DC.COD_FUNDO
GROUP BY FA.COD_FUNDO, FA.NRO_CONTA
)FA ON C.NRO_CONTA = FA.NRO_CONTA
Basically what I want to do is the following : Create a view that returns the data from ALL current accounts and includes the amount invested in mutual funds. Columns of the view: - account number - name of the account holder - current account balance - Total investment fund balance (fundos_aplic.nro_cotas * fundos_cota.valor_cota)
Someone could help me solve this problem ?
In your outermost SELECT you used the SUM aggregation function, however you do not have a GROUP BY clause for this outermost SELECT, you have a GROUP BY clause but only for the innermost SELECT in one of the parts of JOIN. Try GROUP BY C.NRO_CONTA, C.NAME, C.BALANCE.
– anonimo
Hello friend. Thanks for your help. But I still have the same mistake : (
– mateus silva
You may not have posted the full SELECT command because the parenting is incorrect and in addition you call both the FUNDOS_APLIC table and your FA SELECT.
– anonimo
It is complete. What would be the problem with parenting ?
– mateus silva
It is unclear to which you wish to apply this GROUP BY clause.
– anonimo