dbTalk Databases Forums  

Return the result of years in tables

comp.databases.mysql comp.databases.mysql


Discuss Return the result of years in tables in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jifilis@gmail.com
 
Posts: n/a

Default Return the result of years in tables - 06-17-2012 , 03:39 AM






Hi;

I have the table VALUES:

id value date
1 123 2001/1/1
2 6456 2001/1/2
3 125 2001/1/3
4 126 2001/1/4
5 64 2001/1/5
6 128 2001/1/6
7 42 2001/1/7
8 130 2001/1/8
9 564 2001/1/9
10 132 2001/1/10
11 133 2001/1/11
12 342 2001/1/12
13 42 2002/1/1
14 136 2002/1/2
15 543 2002/1/3
16 456 2002/1/4
17 139 2002/1/5
18 140 2002/1/6
19 141 2002/1/7
20 645 2002/1/8
21 143 2002/1/9
22 645 2002/1/10
23 979 2002/1/11
24 456 2002/1/12


I would make the query return this:

2001 2002
January 123 42
February 6456 136
March 125 543
April 126 456
May 64 139
June 128 140
July 42 141
August 130 645
Sep 564 143
October 132 645
Nov 133 979
Dec 342 456


I got back from one year with the query:

SELECT MONTHNAME(date) As Mes, `values`.`value`
FROM `value`
WHERE LEFT(date,4) BETWEEN '2011' AND '2011'

But I could not with all years



Thank you for attention

Reply With Quote
  #2  
Old   
Luuk
 
Posts: n/a

Default Re: Return the result of years in tables - 06-17-2012 , 04:09 PM






On 17-06-2012 10:39, jifilis (AT) gmail (DOT) com wrote:
Quote:
Hi;

I have the table VALUES:

id value date
1 123 2001/1/1
2 6456 2001/1/2
3 125 2001/1/3
4 126 2001/1/4
5 64 2001/1/5
6 128 2001/1/6
7 42 2001/1/7
8 130 2001/1/8
9 564 2001/1/9
10 132 2001/1/10
11 133 2001/1/11
12 342 2001/1/12
13 42 2002/1/1
14 136 2002/1/2
15 543 2002/1/3
16 456 2002/1/4
17 139 2002/1/5
18 140 2002/1/6
19 141 2002/1/7
20 645 2002/1/8
21 143 2002/1/9
22 645 2002/1/10
23 979 2002/1/11
24 456 2002/1/12


I would make the query return this:

2001 2002
January 123 42
February 6456 136
March 125 543
April 126 456
May 64 139
June 128 140
July 42 141
August 130 645
Sep 564 143
October 132 645
Nov 133 979
Dec 342 456


I got back from one year with the query:

SELECT MONTHNAME(date) As Mes, `values`.`value`
FROM `value`
WHERE LEFT(date,4) BETWEEN '2011' AND '2011'

But I could not with all years



Thank you for attention


/me thinks your date format is YYYY/DD/MM ??

SELECT MONTHNAME(date) As Mes,
CASE WHEN YEAR(date)=2001 THEN `values`.`value` ELSE 0 END,
CASE WHEN YEAR(date)=2002 THEN `values`.`value` ELSE 0 END,
CASE WHEN YEAR(date)=2003 THEN `values`.`value` ELSE 0 END,
........
FROM `value`
WHERE LEFT(date,4) BETWEEN '2011' AND '2011'

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.