Questions with Pivot SQL Server Good morning people I’m trying to pivot the table below with the sql server using the VALOR1 Column and ignoring the VALOR2 and VALOR3 column: Before After SqlQuery The problem is that I realized that in order to have one row per year, the VALOR2 and VALOR3 fields must be…
Tag: sql
WordPress Find ID of a Post with a specific meta value
I have about 25,000 posts here (and rising). All of them under a Custom Post Type “lead”. Each post has meta information, including a variable called “uniqid”. this uniqid is a url parameter. now i need the post id where exactly this uniqid exists. Now my question is if there is a way …
Oracle 12 – Reset a sequence Column with row_number() over Partition
I have this table (with order by product, seq): As you can see because of some delete statments I need to reset the seq column and have a seq from 1 for every product/group like this: I tried to create a new counter with this code: and the result was like this: But when I try it with Update I
Postgres – Select days with FAILURE status only
I have table with multiple result per days for particular project_name (SUCCESS, FAILURE, ABORTED, UNSTABLE). I would like to select only days where only FAILURE status occurs – nothing else. There are some days with multiple status (after FAILURE it can be solved and get status with different time and …
Cannot INSERT strings with Set Clause with mariadb connector (python)
I want to insert a new row in my table by using the python-mariadb connector. For that I prefer to use the SET clause. For some reason it does work if I only want to save ints (i.e y=2), but when I use a string, the following error occurs Unknown column ‘myString’ in ‘field list’ It se…
SQL – Select from Multiple databases
I have 10 databases all in the same instance and schema with identical tables. Looking to create a SELECT query which can use a variable of the database names and return all of the records into a single dataset. I’ve been looking around and put the following together as a test (the real select statement…
Postgresql : Query were each join result is a line
I got a database structure with three tables. On table containing some ids and two table containing the same row and a foreign key on the first table : How to get a result looking like this (a kind of left join were each result is displayed in lines instead of in additional columns in the result): Answer I th…
SQL Insert into with join and where
I have three tables. For example: newTable: oldTable: associativeTable: What I want to do now is: I want to move the name column from oldTable to newTable. I have already altered newTable and added an empty name column. Now I’m trying to write a correct INSERT INTO statement. What I have so far is: I…
Checking for different columns OR empty result PostgreSQL
I’m writing some query tests for dbt and I’d like to check that two queries return the same thing and that neither is empty. Since it’s a dbt test, I need to return a row if either of these conditions is false. So far I’ve come up with the following: Theoretically, this should return a…
Split values from many columns accordingly over multiple rows
Firstly i obatin data from Excel and convert them into DataTable in C# project. Secondly i parse this DataTable into JSON string and send it to database as a stored procedure parameter. I want to perform the merge operation on some table with values from this JSON string parameter. Values from this parameter …