将不同的日期显示为列 [英] Display distinct date as columns

查看:64
本文介绍了将不同的日期显示为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,
我有以下格式的表格

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


请建议如何在sql中执行此操作.

Thanx


Please suggest how to do this in sql.

Thanx

推荐答案

您的查询将返回您指定的唯一日期.如果您只想获得唯一的MONTHS/YEARS,则应以某种方式修改日期,使每个日期成为该月的第一天,或者只应使用诸如YYYY-MM之类的字符串表示形式.抱歉,由于我不是在mysql上进行开发,因此我无法为您编写确切的代码,但我认为这应该可以帮助您:)
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


这是一个关键点,请阅读以下内容: http://msdn.microsoft.com/en-us/library /ms177410%28v=sql.105%29.aspx [ ^ ]
This is a pivot, read the following : http://msdn.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx[^]


这篇关于将不同的日期显示为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆