Hope some can help ? I have a 3rd party software were i can do custom sql querys but not able to change any of the database. Struggling to get the result i would like. Do I use GROUP BY or CTE to get the result i need? This give me the result below . I have removed Where c=1
SQL Merge update
my merge query MERGE Povertytgt t USING Povertyrsc s ON (s.Incomegroup = t.Incomegroup ) WHEN MATCHED THEN UPDATE SET t.CountbyGroup = s.CountbyGroup; and got error The …
How delete records from table A and B, if B does not contain specific value
I am trying to compose SQL query for deleting data from two tables – A, B. They are connected with a key and only I need to check, if in B is specific value reservation in one column. Long story short,…
Count times date occurs between two dates in a second table
I have two tables [Charges] and [Defects] and want to produce [Desired Query Output] where the output counts the occurrances of defect when [Charges].ChargeDate is between (and including) [Defects].OpenDate and [Defects].CloseDate. For [Defects] table, a close date of NULL means it has not closed yet. Seems s…
How can i have where clause in Nested queries with select statement that returns more than 1 records
I am currently trying to make an nested query of some sort where it returns a set of rows which fulfills a particular set of requirements.. select * from entity where id = ( select …
How to make preConditions for two columns in liquibase?
I don’t know how to check two columns in table migration. I use liquibase. I wanna to make something like this: “preConditions”: [ { “onFail”: “MARK_RAN&…
Can SQL Compare rows in same table , and dynamic select value?
Recently, i got a table which name Appointments The requirement is that i need to select only one row for each customer by 2 rule: if same time and (same location or different location), put null on …
After adding cursor to this query the execution time went from 10s to 2m.10s
I’m working on this query and after i added the bloc of cursor the execution time goes from 10s to 2m. Is there any way to reduce the execution time? The query is a result of 3 selects on the same table but with different conditions. I needed the cursor because I should get the price of an article from
SQL Join query with a null in Main table
Hi guys so in simple terms I have a Main table “A” and then another table “B”. All the data I want is basically from table A, but to figure one part out I need to join with B. My problem is although the column im joining with a column in B is correct, sometimes the column in A will
Conditional Grouping in SQL
This should be easy, but I’m having trouble with it. I have a results table that looks like this: Notice that the pct column sums to 1.0 for each store. Here’s the code to create this table: I’m trying to group the results by store, then by cust_id while creating a new category A&B if th…