如何将数据行旋转到列并在Gridview中显示 [英] How Do I Rotate Datatable Rows Into Columns and display In Gridview

查看:43
本文介绍了如何将数据行旋转到列并在Gridview中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai all,



我有3张桌子,名为timetablemaster,timetabledetails和staff。



这是我的桌子结构



timetablemaster



ttId,ttTitle,classCode,sectionCode,startTime,validFrom,validTo,startDate,endDay,noOfClasses





timetabledetails



ttDetailsId,ttId,day,period,subjectCode,staffCode





< br $> b $ b员工



staffId,staffCode,firstName





Hai all,

I have 3 tables called timetablemaster,timetabledetails and staff.

Here are my table Structure

timetablemaster

ttId, ttTitle, classCode, sectionCode, startTime, validFrom, validTo, startDate, endDay, noOfClasses


timetabledetails

ttDetailsId, ttId, day, period, subjectCode, staffCode



staff

staffId, staffCode, firstName


select  s.firstName as Staff, tm.classCode as Class, td.day as Day, td.period as Periods
from timetabledetails td, timetablemaster tm, staff s where s.staffCode = td.staffCode and td.ttId = tm.ttId and td.staffCode like 'S01';







从这个查询我得到这种格式





员工|班级|一天|期间|



Abc | STD1 |星期一| 1 |

Abc | STD1 |周二| 5 |

Abc | STD1 |星期三| 4 |

Abc | STD1 |星期四| 2 |

Abc | STD1 |星期五| 3 |

Abc | STD1 |星期六| 3 |

Abc | STD2 |星期一| 5 |

Abc | STD2 |周二| 4 |

Abc | STD2 |星期三| 3 |

Abc | STD2 |星期四| 2 |

Abc | STD2 |星期五| 1 |













但是我需要在Gridview中以这种格式显示表格





| Monday |



员工名称| Period1 | Period2 | Period3 | Period4 |期间5



Abc | STD1 | STD2 | STD3 | STD1 | STD2





Xyz | STD3 | STD5 | STD1 | STD4 | STD1

Pqr | STD2 | STD3 | STD4 | STD1 | STD3













有谁知道怎么做?非常感谢!




From this query i am getting this format


Staff | Class | Day | Period |

Abc | STD1 | Monday | 1 |
Abc | STD1 | Tuesday| 5 |
Abc | STD1 | Wednesday | 4 |
Abc | STD1 | Thursday | 2 |
Abc | STD1 | Friday | 3 |
Abc | STD1 | Saturday | 3 |
Abc | STD2 | Monday | 5 |
Abc | STD2 | Tuesday| 4 |
Abc | STD2 | Wednesday | 3 |
Abc | STD2 | Thursday | 2 |
Abc | STD2 | Friday | 1 |
.
.
.
.


But I need to display the Table in this format in Gridview


|Monday|

StaffName | Period1 | Period2 | Period3 | Period4 | Period5

Abc | STD1 | STD2 | STD3 | STD1 | STD2
.
.
Xyz | STD3 | STD5 | STD1 | STD4 | STD1
Pqr | STD2 | STD3 | STD4 | STD1 | STD3
.
.
.
.


Anybody know how to do this? Thanks very much!

推荐答案

您的查询将自己获取记录。



使用 Pivot 从行变为列。



参考:

与MySQL的交叉制表(数据透视表) [ ^ ]

http://mgenev.blogspot.in/2010/07/pivot-tables-in-mysql.html [ ^ ]

http://en.wikibooks.org/wiki/Programming:MySQL/ Pivot_table [ ^ ]
Your query will fetch the record as itself.

Use Pivot to change from rows into columns.

Refer:
Cross-Tabulation (Pivot Tables) with MySQL[^]
http://mgenev.blogspot.in/2010/07/pivot-tables-in-mysql.html[^]
http://en.wikibooks.org/wiki/Programming:MySQL/Pivot_table[^]


这篇关于如何将数据行旋转到列并在Gridview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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