I have the following hierarchical structure: Here is the closure table I’ve come up with: I want to remove the link between B and D, and therefore I want to delete the link between A and D (the one of depth 2). The problem is that I don’t want to delete the link between A and D of depth 3
Tag: sql
How can I delete record based on date?
I have a set of data with DateTime type in SQL. I want to delete whatever data belong to a specific date for ex: 2021-11-02 21:07:52.663. if I have value like above I want to delete records using just date. 2021-11-02. Answer This will compare the date part of your datetime to the desired date:
Querying for Unique Values When The Value Exists on Multiple Rows
Thank you for reading! I want to find any value (“Name”), but I don’t want that value if it exists on the same row as a “Type” that equals “Z”. As an example, in the table below, I want all Sam and Joe records, but I do not want any Bob records, because one of the row…
Use having on SQL Query
I’m use the next query to get the average of memory used, but only need get data when average is more than x value And show me the next error Found 1 problemnline 1:152: Cannot use HAVING filter on non-aggregate [@timestamp]; use WHERE instead” And when use WHERE clause, like this Show the next er…
How can I convert a date that’s in “yyyy-mm/dd” to “yyyy-mm-dd”
I have a column that’s called appt_date (varchar(50)) that’s in the format of YYYY-MM/DD and I want to convert it to YYYY-MM-DD I’ve tried several replace, convert, cast functions and solutions found on here but I still end up with the same result. I greatly appreciate the help in advance. A…
Query to sum the top “n” records
I would like to sum the forecast qty column for only the first “n” date records. For example for each item number the earliest(or first) three date records Current Query: Table Desired Result Answer Assign a row number to each record, partitioning by Item (this will start a new row counter for eac…
How to find the max values of each columns using a single SQL query
I have a table, I want to get all the max values of col1, col2, col3 using one query only. I’m using sqlite and flask-sqlalchemy. I tried but then I got [(88,), (30,), (75,), (93,)] I want the output to be [(93,), (88,), (75,)] How can I do this? Answer I think you want three separate calls to MAX here:
REGEXP_REPLACE Strings Starting and Ending with Specific Substrings in Snowflake
I am trying to create a column in a view in Snowflake that replaces any string between strings that I care about with nothing. This is essentially for the purpose of stripping html formatting out of text. As an example: Would should end up like this: Based on the patterns I am seeing, I think that if I can el…
Similiar UPDATE instruction in PostgreSQL
Is there an example of a 2-columns table, (x, y – INTEGER), which given instructions: will show different results? Answer Sure:
How to find out which Foreign Keys to create / reference in existing tables in Snowflake?
We have a lot of tables in Snowflake, none had Primary Keys (I’ve just added them in) but now I’m feeling overwhelmed trying to figure out how to create Foreign Keys without going through each table to see the link between data in two tables? Is there a script that I can create to even do this? P.…