Good morning,
I'm starting to work with SQL and I'm having a problem I need to always bring the last record of a table in the following SQL
I need to bring only and always the first record of this table in bold
Always bring the last result
Good afternoon,
in the UOP_CID_PACIENT table Do you have any field that can be used as a parameter?
For example:
Is it more or less what you want?
in the UOP_CID_PACIENT table Do you have any field that can be used as a parameter?
For example:
And d.dt_incl = (Select max(dt_incl)
from uop_cid_paciente
where cd_pessoa_fisica = d.cd_pessoa_fisica)
Is it more or less what you want?
this, just that,
I just did not understand that part:
Which parameter should I pass?
I just did not understand that part:
d.dt_incl
Hi,
In the example, if your UOP_CID_PACIENT table has more than one record for each patient and you want to always bring the last record of it, you could filter by the date of inclusion of the registry.
SubQuery will bring the last record released based on the inclusion date or another single field that exists in the table.
That is, you will search only the consultations for the last patient's entry.
Now a more "strange" answer:
If you just want the Select to return only one line, you can include another clause A at Query:
- To bring the prime record that you can find:
To bring the last record you would put an order by Field desc
But I guess that is not what you need.
In any case, if you give, explain more in detail what you need.
In the example, if your UOP_CID_PACIENT table has more than one record for each patient and you want to always bring the last record of it, you could filter by the date of inclusion of the registry.
SubQuery will bring the last record released based on the inclusion date or another single field that exists in the table.
That is, you will search only the consultations for the last patient's entry.
Now a more "strange" answer:
If you just want the Select to return only one line, you can include another clause A at Query:
- To bring the prime record that you can find:
where rownum <= 1
and dt_prevista between :dt_inicial and fim_dia(:dt_final)
and d.cd_pessoa_fisica = c.cd_pessoa_fisica
and exists (select 1
from paciente_setor b
where b.nr_seq_paciente = a.nr_seq_paciente
and b.ie_status = 'A')
and a.dt_cancelamento is null
and a.cd_estabelecimento = :cd_estabelecimento
and a.nr_atendimento = c.nr_atendimento
order by nm_paciente
To bring the last record you would put an order by Field desc
But I guess that is not what you need.
In any case, if you give, explain more in detail what you need.
Hello,
I gave an improved and a "wiped" in my code and was like this,
but even informing The parameters the query comes blank, and I do not know what else to do to solve this problem
I gave an improved and a "wiped" in my code and was like this,
select substr(obter_idade_pf(c.cd_pessoa_fisica, sysdate, 'A'),1,100)qt_idade,
substr(obter_nome_paciente_setor(a.nr_seq_paciente),1,60) nm_paciente,
substr(obter_nome_medico_setor(a.nr_seq_paciente),1,60) nm_medico,
substr(obter_desc_prot_medic(a.nr_seq_paciente),1,255) ds_protoc,
substr(obter_desc_cid(d.CD_CID),1,200)ds_doenca,
a.qt_peso
from paciente_atendimento a,
atendimento_paciente c,
uop_cid_paciente d
where a.dt_prevista between :dt_inicial and fim_dia (:dt_final)
and d.dt_diagnostico = (select max(dt_diagnostico) from uop_cid_paciente where d.cd_pessoa_fisica = c.cd_pessoa_fisica)
and a.dt_cancelamento is null
and a.cd_estabelecimento = :cd_estabelecimento
and a.nr_atendimento = c.nr_atendimento
and d.cd_pessoa_fisica = c.cd_pessoa_fisica
order by nm_paciente
-
- Rank: Programador Júnior
- Posts: 20
- Joined: Sat, 06 Aug 2016 9:22 am
- Location: Joinville-SC
- Contact:
Geovani Cristofolini
Consultor de Business intelligence
http://useweknow.com
Consultor de Business intelligence
http://useweknow.com
Oops!
Try as follows:
Try as follows:
select
substr(obter_idade_pf(c.cd_pessoa_fisica,sysdate,'A'),1,100) qt_idade,
substr(obter_nome_paciente_setor(a.nr_seq_paciente),1,60) nm_paciente,
substr(obter_nome_medico_setor(a.nr_seq_paciente),1,60) nm_medico,
substr(obter_desc_prot_medic(a.nr_seq_paciente),1,255) ds_protoc,
substr(obter_desc_cid(d.CD_CID),1,200)mds_doenca,
a.qt_peso
from
paciente_atendimento a,
atendimento_paciente c,
uop_cid_paciente d
where
a.dt_prevista between :dt_inicial and fim_dia (:dt_final)
and d.dt_diagnostico = (
select
max(ultimo.dt_diagnostico)
from
uop_cid_paciente ultimo
where
d.cd_pessoa_fisica = ultimo.cd_pessoa_fisica
)
and a.dt_cancelamento is null
and a.cd_estabelecimento = :cd_estabelecimento
and a.nr_atendimento = c.nr_atendimento
and d.cd_pessoa_fisica = c.cd_pessoa_fisica
-
- Information
-
Who is online
Users browsing this forum: No registered users and 16 guests