Click here to Skip to main content
12,882,493 members (28,210 online)
Rate this:
Please Sign up or sign in to vote.
Hi Experts,
i have a table in the following format
Date               Node  KPI1  KPI2  KPI3
2012-10-11         RNC1   2    5      10
2012-10-11         RNC2   3    5      12
2012-10-11         RNC3   2    6      10
2012-10-12         RNC1   9    1      16
2012-10-12         RNC2   6    2      10

I want to diplay it this way
Node  KPI    2012-10-11 2012-10-12
RNC1  KPI1   2           9
RNC1  KPI2   5           1
RNC1  KPI3   10         16
RNC2  KPI1   3           2

Please suggest how to do this in sql.

Posted 17-Oct-12 21:04pm
Updated 17-Oct-12 21:11pm
Mehdi Gholam334.5K
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your query will return unique DATES, as you've specified. If you want to get just unique MONTHS/YEARS, you should either modify you dates in a way, that each date becomes the first day of the month, or you should just go with some string representation like 'YYYY-MM'. Sorry, I can't write you an exact code how to do this, as I do not develop on mysql, but I think this should get you somewhere :)
SELECT DISTINCT YEAR(date_posted), MONTH(date_posted) FROM table
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170422.1 | Last Updated 18 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100