Skip to content

Tag: sql

Sort by last name and first name

I have a small little problem. I am have a drop down list that displays all of our customers names. As of right now, the list is sorted by last name (A-Z). But for example, there are 250 people with the last name “Smith”. What I need is a way that the last name of each customer to stay the

Split time records across midnight

I’m trying to run some reports and having to deal with the whole issue of employee labor hours crossing midnight. It occurs to me though that I could split the records that cross midnight into two records as if the employee clocked out at midnight and simultaneously clocked back in at midnight thus avoi…

Selecting by month in PostgreSQL

I want to select rows according to the month of a date or timestamp column like this: But I only get error messages in PostgreSQL. How can this be done? Answer You can use EXTRACT function, like this: Your problem comes from the fact that there is no such thing as Month function in PostgreSQL. Check online do…

SQL Top 10 Sales Every Month

Greeting all. I have a SQL 2008 express database, lets name is tbl_Merchant, similar as following: Merchant | Sales | Month Comp.1 100 1 Comp.2 230 1 Comp.3 120 1 Comp.1 …