Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


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.
Posted
Updated 8-Nov-12 7:39am
v2

 
Share this answer
 
Comments
sahabiswarup 8-Nov-12 2:41am    
i have checked PIVOT function but i have found that there should be a aggregate function in PIVOT which i don't want. So how to solve ?
SQL
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;
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900