Skip to content

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…

Postgres window function and group by exception

I’m trying to put together a query that will retrieve the statistics of a user (profit/loss) as a cumulative result, over a period of time. Here’s the query I have so far: SELECT p.name, e.date, …

OPENROWSET – how to read everything as text?

I am using the following command to load data into SQL Server: INSERT INTO [NewTable] SELECT * FROM OPENROWSET ( ‘MSDASQL’, ‘Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:SomeFolder;’ , ‘…

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 …

SQL grammar for SELECT MIN(DATE)

I have a table with structure: id(INT PK), title(VARCHAR), date(DATE) How do I select all distinct titles with their earliest date? Apparently, SELECT DISTINCT title, MIN(date) FROM table doesn’t …