本文介绍了如何将行值转移到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的表格格式

Here is my table format

Seq   Date   Total
1     01-01    7
2     01-02    6.5
3     01-03    6
4     01-04    7
5     01-05    6
6     01-06    5
7     01-07    6.5



如何使用sql获取以下内容?



How to get this following one using sql?

Seq     1       2      3       4       5       6       7
Date   01-01  01-02   01-03   01-04   01-05   01-06   01-07
Total   7     6.5      6       7       6       5       6.5



请帮我解决这个问题.

在此先感谢.



Please help me to solve this.

Thanks in advance.

推荐答案


SELECT '_recording_date' as A,
 [1], [2], [3], [4], [5], [6], [7], [8], [9], [10]
FROM
(SELECT (_morning_milk+_evening_milk) as Total,_sequence
    FROM _milk_yield where _cow_id='8' and _calving_det_id='6') AS SourceTable
PIVOT
(
avg(Total)
FOR _sequence IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10])
) AS PivotTable;


这篇关于如何将行值转移到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:01
查看更多