-2
I would like to show on the screen the 10 highest donation values of each month of the year 2018 table Doacao
.
My database is SQL SERVER. For now I have the following query:
select
datename(month,doacao.Doacao_sdt_Data) as Mes,
pessoa.Nome_Completo,
doacao.valor as valor_doacao,
CONVERT(CHAR(10),doacao.Data, 103) as data_doacao
from doacao
inner join pessoa on (doacao.codigo = pessoa.codigo)
where year(doacao.Data) = 2018
order by month(doacao.Data), doacao.valor desc
With this query I see all donations of each month, and if I put a top (10) at the beginning, appears only the first 10 January:
Below images of the result WITHOUT and WITH the Top:
Result with the TOP:
First, you need to define whether your database is Mysql or Oracle.
– Roberto de Campos
My database is SQL SERVER.
– c3s1
(1) What is the difference between the columns
Doacao_sdt_Data
andData
? (2) How the column is declaredDoacao_sdt_Data
? (3) If the columnDoacao_sdt_Data
is declared as datetime, it contains date and time or date only?– José Diz
this name is wrong Doacao_sdt_date the correct date is actually the date,
– c3s1
@Josédiz I tried to execute, but the error on this line: "seq= dense_rank over (Partition by year ([Data]), Month ([Data]) ' ------>> ERROR: >>> Msg 156, Level 15, State 1, Line 17 Incorrect syntax near the keyword 'over'.
– c3s1
I managed to fix the bug. It worked. Thanks. @Josédiz
– c3s1
@c3s1 I went to check the error and was
dense_rank
when the right isdense_rank()
. I have also corrected in the code.– José Diz
Exactly what I did, dense_rank() It Worked!! Thank you.
– c3s1