Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,how to select monthly data from a table contains data for long time,
for example
field1 = date1
field2 = degree

how to get the max degree for each months (jan,feb...)for certain year and view it in one table.
Posted
Updated 9-Jun-14 19:46pm
v3

try like below
SQL
select max(degree), Format(date1, "mmm")
from table1
group by Format(date1, "mmm")
 
Share this answer
 
v2
Comments
Eman Ayad 5-Jun-14 3:34am    
an error message says undefined (DATENAME),
I used Access database
Sergey Vaselenko 10-Jun-14 10:23am    
Try to use MonthName(Month(date1), TRUE) instead of DATENAME(MONTH, date1).
DamithSL 10-Jun-14 11:33am    
check my updated answer
SQL
SELECT
    DATEADD(month, DATEDIFF(month, 0, t.Date1), 0) AS Date1
    , MAX(degree) AS MaxDegree
FROM
    table1 t
WHERE
    YEAR(t.Date1) IN (2014)
GROUP BY
    DATEADD(month, DATEDIFF(month, 0, t.Date1), 0)
 
Share this answer
 
Comments
Eman Ayad 5-Jun-14 3:43am    
it seems that these functions haven't defined is there another way?
I am using vb.net and Access
Kschuler 10-Jun-14 10:04am    
These guys gave you the basic syntax. If you need the specific function that Access uses, then you should try googling it. I found this link which may help.
http://www.techonthenet.com/access/functions/date/format.php

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900