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 …
get work days function to return whole number on sunday
The function number_of_days(start_date, end_date) should calculate how manny work days are in between start_date and end_date. It wroks for whatever start_date as long it is not sunday. Calculation …
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…
How to select records from a Postgres table using an ORDER BY statement on a jsonb column that points to another table
I have two tables, characteristics and students. characteristics students The characteristics table has three columns where the id column is an auto-increment field. The name denotes the name of a specific characteristic and the value indicates the respective information about the characteristic. The students…
How to select the row with the max column from another subquery in Oracle
Basically I’m trying to find the max of a count outcome. Here’s an example: Desired output: the name of the employees with the highest number of jobs and the number of jobs done. My tables (bold …
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
Query to find the count of total IDs, and IDs having null in any column and the percentage of the two (i.e. Count of ID having null /total ID count)
There are two tables. Tables A has following structure ID Flag Name 1X 1 Y 2Y 0 Null 3Z 1 Null 4A 1 Y Table B has the following structure B_ID City State 1X Y Null 2Y Null Null 3Z Null Y 4A Y Y I want to get the count of all the IDs and the count of IDs
Postgres query return nothing where there should be a valid data
I have a query that should return some rows, but it returns blank. As far as I know .. the pictures down will show the issue. Here is the query This is the table : I tested the calculation and it worked a lone . Answer Your condition cannot be right because you are comparing M.PLAYED_AT to be BETWEEN M.PLAYED…