On Mon, Jun 6, 2022 at 10:06 PM Thiebo <thiebald.crem...@gmail.com> wrote:
> Hello, > > I'm trying to do this SQL request (postgresql) : > > select SUM (montant) AS solde FROM entrees WHERE account_id = 1 and > date_de_valeur >= '2022-02-01' and date_de_valeur < '2022-03-01' > > Reading the documentation on virtual rows, I do this in Sequel: > > DB[:entrees].select{[sum(montant).as(solde)]}.where{(date_de_valeur >= > '2022-02-01') & (date_de_valeur <= '2022-03-01')}.where(account_id: > 1).map(:solde) > This generates the following SQL: SELECT sum(montant) AS solde FROM entrees WHERE ((date_de_valeur >= '2022-02-01') AND (date_de_valeur <= '2022-03-01') AND (account_id = 1)) The only difference I can see is you are using <= instead of < for '2022-03-01'. Maybe that is what is affecting your results? That last query return an erroneous result. What am I doing wrong? > Hard to tell for sure. I would guess the difference in operator causes it, but you don't mention how the result is erroneous (what you expect vs what you received), or provide a self contained example (e.g. create tables, populate data, then run query) to enable debugging the issue. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSSfiLNYkDv8dje_sg-E4D6NPD%2Bc-%2B5hywVko2B_uKTzhtA%40mail.gmail.com.