在sql中进行透视和透视 [英] Pivoting and unpivoting in sql

查看:122
本文介绍了在sql中进行透视和透视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IngredientName NUTRIENTNAME NValue

MILK牛的碳水化合物4.4

MILK牛的异亮氨酸0.173

MILK牛的丙氨酸0.107



i有上表。我需要像下面这样转动它。



IngredientName碳水化合物异亮氨酸丙氨酸

牛奶牛奶4.4 4.473 0.107



如何执行此操作?

IngredientName NUTRIENTNAME NValue
MILK cow's Carbohydrates 4.4
MILK cow's Isoleucine 0.173
MILK cow's Alanine 0.107

i have the above table. i need to pivot it like the follwing.

IngredientName Carbohydrates Isoleucine Alanine
MILK cow's 4.4 0.173 0.107

how can i perform this operation?

推荐答案

select IngredientName ,Carbohydrates,Isoleucine , Alanine   from(select  IngredientName ,NUTRIENTNAME ,NValue from table1)
 up PIVOT (sum(Nvalue) for NUTRIENTNAME in(Carbohydrates,Isoleucine,Alanine)) as Pvt 


这篇关于在sql中进行透视和透视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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