Skip to content

Tag: sql

marked user with label by time for each month

Data source User ID Visit Date 1 2020-01-01 12:29:15 1 2020-01-02 12:30:11 1 2020-04-01 12:31:01 2 2020-05-01 12:31:14 Problem I need advice im trying to do sub query for this result to mark user as retention if they havent visit back for 3 month. i using this query for the data to get user’s latest vis…

Turn Cross Apply opensjson results into columns

We have a table that has a field with some json. using cross apply I was able to turn those pairs into columns: So how do I turn this into something like : Thanks. Answer If you know the limited set of possible key names in advance, you can just use PIVOT: But you can’t write a PIVOT if you

How to count number if special type of value by day in SQL?

I have a table in my database which looks like this: I want to get table with number of upload value_types per day (my time column is not per day as you see). So for this example it must look like: How should this SQL query look like? I dint understand turning time into days part especially. Answer You seem

How to perform Case statement inside a select statement?

I wanted to put ‘No record’ on the column instead of NULL if the datediff function returns a null value. So far this code only throws Incorrect syntax near ‘CAST’, expected ‘AS’. but I don’t know what data type should I put in the CAST parameter , since if there&#8217…