I am trying to create a “where clause” that can handle multi-valued parameter but not getting it to work. With the above sample table I wish to create a query that filters the rows with colors red and blue using a variable parameter like the following: I tried using the STRING_SPLIT function but d…
Add column to table with existing data in SQL Server
I have a table Rates with data in it and I need to add new column to the table however I get the error: ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the prev…
Extract number between two characters in Hive SQL
The query below outputs 1642575.0. But I only want 1642575 (just the number without the decimal and the zero following it). The number of delimited values in the field varies. The only constant is that there’s always only one number with a decimal. I was trying to write a regexp function to extract the …
How to select students with marks in all three subjects less then 100
I came across this question Here is my response to it, I just started myself learning SQL recently. Select a.roll_number , a.name , b.roll_number from student_information a join …
How to group consecutive rows with same values in a result table into groups with date_from and date_until
I have a simple database table (Postgres) consisting of 3 attributes (f1,f2 and f3) ordered by date. (dbfiddle). I want to transform (group?) the result into the following table: f1 f2 f3 …
Failing to produce or update a table row using a trigger in SQL
I am trying to create a trigger in Oracle SQL 12c. The concept is that i have two tables, a storage table (Storage) that holds items and a delivery table (Supplier_Orders) that notes how many items(…
Creating a scope in Ruby on Rails, that returns an instance of an object only if all the associated instances fit a certain condition
I have a table called Carts with a has_many relationship to another table called Subcarts. I want to create a scope that returns all instances of the Cart table where all the associated Subcarts fits …
How to delete a row from a relationship table using two columns
I’m trying to delete a relationship between table T2 and T3 that is on table T1. I’ve searched but I could only find examples of a DELETE with only one INNER JOIN. I’m trying something like this, but I get a error: SQL error: ORA-00933. 00000 – “SQL command not properly endedR…
How to find the most appropriate date between overlapping date periods in mysql
I`w got an 2 tables with such data: Table 1 id s_id s_date 1 33 2021-03-05 10:36:59 2 33 2021-03-06 10:36:59 3 33 2021-03-09 10:36:59 4 33 2021-03-10 13:36:59 5 33 2021-03-11 12:36:59 6 33 2021-…
SQL in Excel: Cannot call declared variable
I am trying to breakdown my SQL string in Excel VBA, storing my variables in the first part of the SQL, and calling them in the second part. It seems that declared variables is not my friend here? First part(Declaring my variable) Second part(Calling my variable) Using a temp table works: But calling the vari…