I have the following tables: COURSE_PREREQUISITES My question is: How can I obtain all the course ids a student needs to take before he can take course id 6? Intended Answer: I should obtain the course id of 1, 2, 3, 4, 5. Attempts Made: I have tried selecting the prerequisite_course_id of the intended final …
Tag: sql
Get total Sum from SQL Query of two tables
I have two tables which are as follows: Table1 and Table2. Table1 : Table2: I want a SQL query which would show me the result in total manner. The Output that I want is : I have done it using the PowerBI and I know it can be done using SQL too but I am not able to achieve it.
Select row in group with largest value in particular column postgres
I have a database table which looks like this. I need to group this table by id and select particular row where time_point has a largest value. Result table should look like this: Thanks for help, qwew Answer In Postgres, I would recommend distinct on to solve this top 1 per group problem: However, this does …
Sql pattern in like condition
Simple issue : I have fields (path) like : I want to be able to get the path containing 43/XX Meanings here the only valid one would be This seems not to be working Answer Only SQL Server supports using (a small subset of) regular expressions with LIKE. In MySQL, you would use RLIKE, or REGEXP (both are synon…
Shifting the total group by 1 step- MYSQL [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question Here I have name and pay as columns of a database table. Table has Name an…
In R how to make a string of fields in to a SQL join
In R given a string like “fld1,fld2” how can I get something like “b.fld1=v.fld1 and b.fld2=v.fld2” for a SQL query. The string may have up to 10 distinct elements. This is for trying to build a join on the fly. b and v are the aliases for two tables. There willo only be two tables. An…
Problem with Concat results searching in MYSQL
Hi this is the query I’m trying to achieve results with but how can I get the search for concat results in that column? Answer You can’t refer to an alias defined in the select clause in the same scope (left apart the order by clause). In very recent versions of MySQL (8.0.14 or higher), you can u…
specific day of next month on a sql query
I have a complex (complex because it gave me lots of work to complete!) and it returns results that fulfill the query till the day 30 of the current month. Here is the code: I have a job that runs this query on the third monday of every month. What i need is that the query returns values not only
MYSQL – Fetching entities whose many-to-many relationship contains all terms collectively
I am using the following DB Schema and using something like this to add data/query it which returns How can I return recipes who’s ingredients are a subset of a list of ingredients provided? e.g I should not return Chocolate cake if list (egg, salt, sugar) is provided. However I should return Chocolate …
How to check json format in SQL?
I have a table with a column of type Nvarchar where json is stored. But the format of some of its columns is wrong. So I get an error when I parse them all. I want my query to ignore lines that have errors. It gives this error when I run on all lines: JSON text is not properly formatted.