I have this table Id item type A itemA1 X A itemA2 X B itemA1 X B itemA2 X B itemA3 Y And i would like to create new indicator which contains the information about if the Id contains only item of type X or only tpye Y or both like this : Id Indicator A Only X B Both
Tag: sql
How to include the code into a REPLACE function in oracle?
User @psaraj12 helped me with a ticket here about finding ascii character in a string in my DB with the following code: The script looks for characters of a certain range GROUPs them and marks displays them. Is it possible to include this in a REPLACE statement of a similar sort: EDIT: As per @flyaround answer this is the code
Is it Possible to save results from a CASE Query in a Table?
Is it possible to make a case query and save it also into the table in the same query? thanks for help! Answer You need to use INSERT INTO
Getting peak hourly KW for each month and showing the year, month, day, and hour it occurred for past 10 years?
I have electric meter usage data for 22,000 meters that goes back 10 years (2012 to present) and it’s stored as hour intervals. So, each individual meter will have (10 years * 365 days * 24 hours) 87,600 records – one for each hour going back 10 years and the KW (usage) for that hour is recorded. And for each
Order and limit data based on JSONB array
I have such a PostgreSQL table Now I would like to get all sorted val and have the limitation for each query (for pagination). For example 1st query 2nd query Answer You need to unnest the array, sort the result then apply offset and limit: Instead of limit 5 you can also use the standard compliant fetch first 5 rows
Parse text and special characters from SQL Server
I have an issue with parsing text with special characters from XML in SQL Server. Let’s say I have a XML file Sample.xml which has the following data: I prepared the following SQL script which can parse everything except two sentences in the <TextType> attribute: First sentence to retrieve Second sentence to retrieve Could you please help me to add
Generalized way to remove empty row given by aggregate functions
Example: The below query would give an empty NULL row when no data is present. The NULL row result looks like this: MaxNumber 1 NULL To detect if the query returns data or not I had to do this: Returns 1 if a max number exists and 0 if empty table. Is this how we generally tackle the empty row
Production amount each year by ID and Date
I would like to get yearly production growth amount based on ID and DateTime. In the above example, for the ID – 1, it is showing perfect (705+326=1031). But for the ID – 104, it is not showing right answer like (10+54=64). where is the wrong in my SQL query below to get the annual production growth amount by Date
SQL divide count grouped by the same value from different columns
So I have a table with two rows containing names and some other stuff, these two columns can contain the same name: Buyer Seller RegionID … John Lina 1 Lina Kajsa 2 John Conny 5 Kajsa Conny 3 John Erik 2 Kajsa Conny 1 John Conny 2 John John 1 John Conny 1 Kajsa David 1 David David 1 Lets
ORACLE CONVERT CHAR FORMAT “YYYY-WW” TO DATE FORMAT
I am trying to convert char date format “YYYY-WW” in ORACLE to date for calculating by week in year but have a trouble with error message format code cannot appear in date input format If i write It will be normal But if i write The message error format code cannot appear in date input format appear. I don’t have