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 …
Tag: sql-order-by
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 …
subquery shows more that one row group by
I am trying to get the data for the best 5 customers in a railway reservation system. To get that, I tried getting the max value by summing up their fare every time they make a reservation. Here is the code. this throws the error:[21000][1242] Subquery returns more than 1 row If I remove the group by from the…
Add and update a column with sequential numbering based on grouping
I have a table with following structure Id Division Details 1 A some text 2 A some text 3 B some text 4 B some text 5 B some text I need to add a new column of integer type named “Order” with some data as described below: Id Division Details Order 1 A some text 1 2 A some
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 …
d6 delta query – get the latest entry
I’m working on a query but I’m running into an issue with deltas and getting the latest info. If I have a table as such…. I’d like to get results like: I want the latest delta that has a value per ID. I’m writing this in postgres but running into some issues. Any suggestions? Ans…
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 …
DISTINCT work differntly in MYSQL & POSTGRESQL
I have created a sample table report in SQL and filled sample data in it using the following command. I need to find the list of recently visited(based on date column) branches with out duplication. So I used the following query It works on MYSQL but shows the following error on POSTGRESQL. How to fix this? O…
How to get next item in mysql order by createdAt
My frontend app can list of my items order by createdAt (for sure by calling API): Output is for example: Id of each item is UUID (there in example just myId*). I can open detail of item by url /item/detail/myIdPPP and on this detail I have GO TO NEXT item. The problem is, that I don`t know how to create