Skip to content

Tag: sql

Use of ORDER BY returns column filled with NULL

I have to do the following exercise: Write a SQL query to list the names of all people who starred in a movie released in 2004, ordered by birth year. Your query should output a table with a single column for the name of each person. People with the same birth year may be listed in any order. No need

SQL – Inster into with now() minus one day

I want change this request. Actualy this request insert into always 2021-11-11 at 10:50:00 I use a script.sql for my H2 database (continous delivery). I want change my request to Now() minus one day at 10:50:00. Answer Subtract a day from the current date, then add the time.

Check value of last 4 rows

I want to check the value of the last 4 rows from DB. If these 4 rows have a specific value, Do something. So the table looks like this: Here is a fiddle to test with: http://sqlfiddle.com/#!9/1064b3/1 I can run the following query SELECT * FROM testing ORDER BY id DESC LIMIT 4, Then check with PHP: Is there …

Using one query’s result into another

I have this query which shows the below result, I want to use this MarksObtained and take out min, max and avg of each course and show it with the second query (have provided below). This is the second query So it will basically show min, max and avg of each course achieved by the students. What I want: Sampl…

SQL Error 3780 when using foreign key as primary key

I’m getting the following order trying to use a table’s primary key as another table’s primary key: ERROR 3780 (HY000): Referencing column ‘optimization_id’ and referenced column ‘optimization_id’ in foreign key constraint ‘optimization.main – optimization…

Adding time to a table in SQLplus without date

I am trying to create a table regarding telecommunication and I want to add time for 2 rows call_start_time and call_end_time and with that, I want to calculate the call_duration. This is what I used to enter the value If I use this format while displaying the data only the date is displayed not the time. Can…

I can not convert the data to the required form

Hi hi I have a Nodejs server and I am using PostgreSQL, the bottom part of my database. How can I select data and represent it like this (in one sql query): I wrote a request but it is far from what I need: Answer You can use a cte to first build the question JSON data, and then aggregate