Select data by month [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I Need help to select a number of data per month, there are 4 retailers and I need to select a total of transactions per month and the total amount for that month showing each month separately in sql.

Extract the month from the date and group by it. Then you can use aggregate functions to sum and count
select month(date_column),
sum(amount) as total_amount,
count(*) as transaction_count
from your_table
group by month(date_column)

Related

Get Sum & Average of each month using SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have below database table,In here i need group some data and get sum and avg of some data.
In here i need to calculate Item marketers monthly sales(Each Month)
As a Example :
I need to get a Patric Newton's Sales in Each months.
And also i need to calculate AvarageFactor of each month Each employee.
AvgFactor = SUM(Daily Sales)/ SUM(Value Factor) * 100( Each Month )
Database Table
I have tried it like below,
SELECT ItemMarketerName,DailySales,ValueFactor,[Month],[Year]
FROM [SR_Hotel].[dbo].[Table_1]
WHERE ItemMarketerName IS NOT NULL
Group by ItemMarketerName,DailySales,ValueFactor,[Month],[Year]
Order by ItemMarketerName
You should not include your aggregated columns in your GROUP BY.
Try:
SELECT ItemMarketerName, [Month], [Year], SUM(DailySales), SUM(DailySales) / SUM(ValueFactor) * 100
FROM [SR_Hotel].[dbo].[Table_1]
WHERE ItemMarketerName IS NOT NULL
GROUP BY ItemMarketerName, [Month], [Year]
ORDER BY ItemMarketerName

SQL query to find current month from date [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
The question is to Produce a list of the latest movies by genres for the current month. How to find the current month from the Date???
You are looking for DATEPART()
Select
*
From YourTable
Where
datepart(month,ReleaseDate) = datepart(month,getdate())
and datepart(year,ReleaseDate) = datepart(year,getdate())
Order by Genre, ReleaseDate desc
You can try this:
SELECT SUBSTRING(TO_CHAR(now(),'YYYYMMDD'),5,2)
In which:
Format to date and you get only the month

Display bookings for first of every month [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm trying to display hotel bookings from the 1st of every month.
Hotel (hotelNo,hotelName,hotelAddress)
Room (hotelNo,roomNo,type,price)
Guest (guestNo,guestName,guestAddress)
Booking (hotelNo,guestNo,dateFrom,dateTo,roomNo)
Here's what I have so far. Obviously it isn't working. How do I select the first of any given month?
SELECT hotelNo, dateFrom
FROM booking
WHERE datefrom >= to_date('01', 'dd');
If you want records that are on the first day of any month, then you can EXTRACT the day part of the date and compare it with 1:
SELECT hotelNo, dateFrom
FROM booking
WHERE EXTRACT(DAY FROM datefrom) = 1;

I dont know sql syntax for my table [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table
ID______credit________paydate
------------------------------
101_____10____________2012/01/01
101_____13____________2012/02/01
101_____8 ____________2012/03/01
101_____3 ____________2012/03/01
101_____22____________2012/05/01
..._____..____________..........
..._____..____________..........
999_____13____________2012/07/01
999_____38____________2012/08/01
I want to select all records for last 3 months(it is different last paydate for every ID) and where credit < 10
can someone help me with this??
thx and regards
You could use the DATEADD function to get the desired result:
SELECT *
FROM table
WHERE paydate >= DATEADD(month, -3, GETDATE())
AND credit < 10

Selecting timestamp records in postgres [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I select records in Postgres that have hour values greater than 00:00:00? The field type is Timestamp with time zone.
Example record:
"2012-07-30 07:00:00-07"
I need everything that is greater than 00:00:00
Use extract(hour from ...). See the PostgreSQL date/time functions in the user manual.
CREATE TABLE test AS SELECT TIMESTAMP WITH TIME ZONE '2012-07-30 07:00:00-07' AS tstamp;
SELECT tstamp FROM test WHERE extract(hour from tstamp) > 0;