ORDER BY DECODE: Decode won’t reorder the days like I want it to

I’ve got an assignment where I need to return a certain report and then order it by the day, but I need Monday to be day #1 (by default, Sunday is day #1 in SQL). Here’s my code for the report and the …

Should the column used to order results be included in the index of a postgresql table?

I am creating indexes for a PostgreSQL database. I would like to know whether the column(s) used to order results in a PostgreSQL statement should be included in the index. Assume I have created a …

Calculate order sequence in BigQuery

I am new to BigQuery SQL and struggling with calculating an “order sequence” from a table of customer orders. In my example, I am working with customer purchases, where I have the sales …

SQLite – order by numbers inside string

its my first post here, so bear with me. I’m trying to order a query by numbers in a specific row that contain letters, using SQLite. Example: “Winter 1993”. I want to be able to sort by the …

MySQL: Select penult values

There are 2 tables: table1: id |phone| order| —|—–|——| 1 | 122 | 6 | 2 | 122 | 4 | 3 | 122 | 3 | 4 | 123 | 6 | 5 | 123 | 5 | 6 | 123 | 3 | 7 | 124 | 6 |…

How can I select the max for a maths operation and also other elements without the max displaying all results

I am trying to find the maximum value of something, while also selecting other attributes at the same time. When i do the max statement on its own, it works as intended, but when I select another …

Select longest duration time (data type field) and client name SQL

I have these tables: CREATE TABLE Client ( client_id NUMBER(10) NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, address VARCHAR(50) NOT NULL ); CREATE TABLE Projects ( project_id …

Can you use ORDER BY (column) LIMIT with a secondary column?

I want to find out the Top 10 rented movies in the sakila db. It must be sorted DESC after total_rentals and secondary after film title. My solution looks like this and works so far without the film …

Is there a way to order by value increase compared to older entries in MYSQL?

I want to order each ID by the percentage increase in a three day timeframe. If there is no entry three days ago, it should move up the date until today’s date. In the following I have explained the …

Order by with formatted dates, doing it right?

I wanted a mere sanity check because I have a slight feeling I am doing it all wrong. I stripped down the use case to a very simple sample. When formatting a date I need to cast the data in the order …