Skip to content

Tag: sql

SQL Query for Events table

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…

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&#8217…

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:

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…