Skip to content

Convert Query Using Case Statement

select sum(DATEDIFF(“D”,M.ActiveStart,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) – 1, 0))) as Duration_Days , m.HomeBranch, m.LocationName from AX.Memberships M where m.ActiveStart < DATEADD(…

Trying to get Price Difference and Percent Difference

I am trying to find the daily price difference and the daily percent difference, in one field, in one table. Here is the code that I am testing. Here is a sample of my data (first three fields), with the expected results (last two fields named ‘PriceDiff’ & ‘PercentDiff’). I am usi…

MySQL self join to find only the next revision

Actually I’m working with WordPress. I want to create a self-join or something similar to find a revision of a post, and the following revision of the same post. https://www.db-fiddle.com/f/eHnwYABYrVVQAhn8xLJ77q/1 The previous query doesn’t work since it takes, for every record of a, all the revi…

Sequence Numbering in SQL Server

I have an table (always ordered by ID ascending) with 5 records as such : ID Sequence 1 1 2 2 3 3 4 4 8 3 9 3 And the desired output is : ID Sequence 1 1 2 2 3 3 4 6 8 4 …