I have an event table in Postgres, with this structure: This works as a log, so all entries are immutable, change is status will be another INSERT. I want to efficiently extract all events which have status CREATED, but not DONE. Answer I assume that you want ITEMs that meet the conditions. If so: This uses t…
Tag: sql
Swapping one column to another
There are n number of parent tasks and each task has their actual start time and actual end time, now there are child task as well, for one parent task which ends with ‘createprovision’ i want to replace the end time with the start time of the child task which starts with ‘Preparations’…
How to group by row in diferents columns
I have this table in SQL, I need to group it by the report name and I need to split the price_bucket column and the count_sales column in diferents rows. I think that I should use the PIVOT funtion in SQL Server and an intermediate table. How should I do it? This is what the final table should look like:
Eliminate the rows that becomes same after swapping as in original table in SQL Server
I have a table which contains data as follows: I want a table which do not have Mumbai—>Jaipur as it is present already before being swapped. Similarly, Lucknow—>Indore is not required. All other entries must come as it is which is there in the existing table. Can any body help. Note: Table …
SQL – Column containing current firmware string based on occational messages with several machines
I have a table called SessionEvents. I’m trying to create a column that represents the firmware that is on the machine to later be able to filter messages for only certain software. Currently my SQL query looks like this. (Based on answer by adamlamar in How do I efficiently select the previous non-null…
Return word with the capital letter from string
I have a column like: How to get: Assume there is only one word with the capital letter per string. Answer You would need PATINDEX (to find any of the capital letters within the string), CHARINDEX (to find the position of space after the capital letter or end of the string) and SUBSTRING (to get the part of t…
Combining query results for number of records in a single row
I am new to SQL. I have a table that has billion of records with multiple columns, let’s say a,b,c,d,e,f. I would like to create a query for number of records for each column with certain condition …
Is there a way to use a table value attribute in where clause in SQL
I’m very new to SQL and i feel like this is a dumb question because I couldn’t find an answer to it… I have this table in a SQL query: CREATE TABLE MOVIE ( TITLE VARCHAR(255) NOT NULL, …
APEX: Submit without refreshing the page
I have an interactive report that runs a large query, which takes about 20 seconds to execute. There are many filter items on the APEX page, which affect the data in the report. The report uses a PL/…
What’s the most efficient way of truncating the names in a first_name and last_name column to 1 character?
What’s the most efficient way of truncating the names in a first_name and last_name column to 1 character? I have a mysql database that I want to hand off to a developer but I want to partially …