My table (Table1) I did a sort of Pivot and it’s fine: http://sqlfiddle.com/#!18/45b9d/1/0 Now I need to calculate the difference between measures, to get something like this: But if I don’t use an aggregate, the result brings me null cells – http://sqlfiddle.com/#!18/45b9d/5/0 And if I do u…
CTE Recursive Query to Grandparents
I have following table: What I need to get is SELECT query that will return only rows that have ISDELETED 0 and ISINEDIT 0 and whose parents or grandparents are 0 as well I currently have: But for some reason it returns double rows Answer You need to add the same isdeleted = 0 AND isinedit = 0 predicate to
SQL Data range using Case
I have table1 with data Age 10 21 35 50 and my query select count(*) as Total, * from ( select case when age <18 then '0-20' when age between 20 and 29 then '20-29' when age between 30 …
Count json tags in sql
I have this json strings And know i want the following output I wanted to do this with a sql query. If you know how to do this, thanks in advance! Answer If you’re not using MySQL 8, this is a bit more complicated. First you have to find a path to a name element that has the value phone
SQL, Determine if Records in Table A exist in Table B
TableA has columns AccountNum and RoutingNum TableB also has columns AccountNum and RoutingNum Table B is more trustworthy. So, I would like to find if all records in Table A exist in Table B. And if not, which records do not match. Is this on the right track? Your solution would be greatly appreciated. Answe…
Find all records that have X tags ordered by ascending time, BUT, the ones that match the most tags should be grouped first
Ok, this is a little hard to explain, and the title is not the best :/ but, basically, I have 3 tables and I’m trying to write a query that returns them with 2 levels of ordering. The first by the amount of “tags” each row has, and the second by when that row was created. And I would like
Update column data using SQL query
In our SQL Server database, we are trying to update the old column data in a table. In a table there is lot of data similar to Agency Administrator. This is data is in old format where we were taking single values in a column. Now, due to an update in data structure, we are storing the data as [“Agency
how to find the average of first 3 rows using avg() function in MySQL
I have table called student, and which there is field of marks. i’m trying to get an average of first 3 marks. +———–+ | MARKS | +———–+ | 34.8771 | | 34.8282 |…
SQL Insert with Inner Join trying to insert into wrong column
I have an existing table of products, and I’m trying to insert new attributes from other tables into my main product table. Here’s my query: The error that I get is: Field ‘product_id’ doesn’t have a default value. I’m not trying to insert into the product_id column, I̵…
Select row where column is different from previous row
I am trying to write a query to track the changes of a boolean column in a table. The table looks like this So what i would want is row 3 where the is_active changed to false. Then after that i would want the next row where it changed to true again. This is what i tried: So the subquery