I have a set of data where value is calculated starting from 1 – 12 then moves 1 step down and calculates another 1 – 12. This works well in Excel however how do I achieve this in SQL. Is it even possible? I have tried which gives me a list of numbers then restarts after 12 so I want
Tag: sql-order-by
How to order a query result by two columns with nulls last in one of the columns
I have the following table ‘client’ I want to fetch all rows from this table ordered by ID Desc, with nulls in the column filecount ordered last. So after the sorting I would like to get the following order: I tried the following but it doesn’t work: Answer I would use a CASE expression here: Demo
using ORDER BY in SQL for chunks of data
I want to know how I sort data in a SQL query but only in certain chunks. I’ll provide an example to make it easier. In the above example, I want to do an ORDER BY height DESC, BUT only the tallest person of each rank gets ordered and everyone else in the same rank is right under that person
Select every second record then determine earliest date
I have table that looks like the following I have to select every second record per PatientID that would give the following result (my last query returns this result) I then have to select the record with the oldest date which would be the following (this is the end result I want) What I have done so far: I have
SQL Order By in Custom Sequence [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I have data in this order How can I sort this data in this order? Answer To do this requires a big assumption which is
Join on multiple columns and in one of the integer columns join by choosing minimum difference
I got table t1 and i want to join it with table t2 below on columns a, b and c +———+———+———+ |a |b |c | +———+———+———+ |473200 |1 |1.-1-…
Create a descending list of orders per item and display the ranking position in seperate column
DB-Fiddle Expected Result: In the results above I want to create a descending list of all orderIDs per itemID. Starting from the newest order to the oldest order which is defined by the event_date. The position of an orderID within a certain itemID should be displayed in column position. I tried to go with this query but could not make
Sort by year as nvarchar and then numerically
I have an nvarchar column that in essence stores the following data: The first two numbers represent the year created and the last numbers represent the id of the unit made that year. Whenever I sort I get the 99’s first and 19 last. I’d like to sort by latest year first and then numerically. I have tried converting to
How to Sort this MySQL Query
I am trying to insert the ORDER BY in this query to sort the Total column: With the following result: Here’s what I have tried so far but no luck: Answer I think you want: Rationale: the ORDER BY clause should go after all UNION ALL subqueries – so it needs to be outside of the GROUP_CONCAT(), in an outer
How to understand the execution sequence of SELECT and ORDER BY
I googled the question and all answers said SELECT was executed before ORDER BY. But the simple example below (using MySQL and sakila database) gives the correct sorted results. Obviously, ORDER BY is not executed after SELECT, as customer_id is not selected by SELECT. Can anybody explain what happened? SELECT rental_date FROM rental ORDER BY customer_id LIMIT 10; Answer Is