Skip to content

Sql – Query to calculate no. of buyers monthly

i would really need your help in creating a query where i can show the number of buyers who made more than 1 order in a month for the period January 2017 to December 2017. Also, the no. of these buyers that didn’t order again within the next 12 months. Below is sample my data. Date CID (customer id) Ord…

Query to display Employee and Manager

I have to write a SQL Server query to display the employee last name and his respective manager’s name, as given below. These are the schema for the two tables. Expected Output : I tried this code but its not right Detailed Schema: Schema Answer I guess something as simple as this should do it How it works: T…

verify flag for user as parameter

I have table users Userid flag 145 1 142 0 a second table Sales salesId date amount 252 01/01/2021 125 23 01/02/2021 300 I need to ckeck each time for user parameter …

Count number of students per one role SQL

I have a table students with student id, course id and role number looking like this (ordered by student_id): How to count number of students for each role? If student is enrolled in multiple courses with the same role number, then count this as one. The expected output for above table would be similar to thi…

Set minutes of timestamp to a specific value

What is the easiest way to set the exact minutes value of a timestamp? This only adds minutes instead of setting the exact value: Answer Use date_trunc() before you add 2 minutes: Or, to retain seconds and sub-seconds: Demo: Should be substantially faster than manipulating the text representation and casting …