Skip to content

Tag: sql

MySQL: Find the last event where the user was tracked

Let’s say your web application tracks the activities of its users using a tracking system. While a user hasn’t logged in or signed up, all the user’s actions are tracked using anonymous_id and the user_id is null, and afterward, they are tracked using the same anonymous_id and user_id. It is…

Partial Group Filter

Oracle 11g How can I get ALL pet_owners of FURRRY and SCALY and only earthworms and slugs ? Answer You want either of the two conditions to be met, so you need OR:

Check if a pair of records belong to multiple group IDs

I have a table that contains 2 IDs – UserID and GroupID. I need to pull a list of all UserIDs that “share” the same GroupID at least 4 times So, based on the following data set: I’m trying to generate the following result: UserID A UserID B NumberOfOccurrences 1 2 4 2 3 4 1 3 5 I&#8217…

Finding Active Clients By Date

I’m having trouble writing a recursive function that would count the number of active clients on any given day. Say I have a table like this: Client Start Date End Date 1 1-Jan-22 2 1-Jan-22 3-Jan-22 3 3-Jan-22 4 4-Jan-22 5-Jan-22 5 4-Jan-22 6-Jan-22 6 7-Jan-22 9-Jan-22 I want to return a table that wou…

how to single out certain names in sql

So I have this problem in SQL where the question is this: List the sId and name of students that applied to “WSU” But not “U of O”. and my attempt was this: However this does not do the trick as it doesn’t catch that some of the students had already applied to U of O. MRE: And then of

Calculate number of times a user visited a page in SQL

I have table as shown below. It has 3 columns user, page and timestamp. In the above table I want to calculate number of times a user visits a particular page. Each record in the above table is a hit, so just grouping by column page wont help. I essentially want to count continuous records for a particular pa…

When do Postgres transactions fail?

I was wondering at what point a transaction actually fails in Postgres. By this I mean stop working, and return an error. Is it after the first failed query? Does it try all queries and then return failure? Hopefully it fails fast on first failed query, but I don’t know for sure. For instance, if I have a tra…