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 …

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 …

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 …

SQLite: Order by number of NULL values

In SQLite, is there any way of ordering by the number of NULL values in each row, without having stored this number explicitly in a separate column? Something like SELECT rowid FROM (SELECT rowid, …

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-…

update max id_post only from table in job crons, mysql

I have a table posts id_post | status 3434 0 5655 3 5935 5 9867 1 9990 3 10975 5 11234 3 Im running a job cron to update every …

SQL order with equal group size

I have a table with columns month, name and transaction_id. I would like to count the number of transactions per month and name. However, for each month I want to have the top N names with the highest …

How do I sum up each Month of data for each product?

I have a set of data such as: Date Product Volume 01-01-2020 A 5 02-01-2020 A 25 03-01-2020 B 20 02-01-2020 B 10 04-01-2020 C 5 02-02-2020 …