SQL(按产品交替排) [英] SQL (Rows alternating by product)
问题描述
嘿所有!
我有一个我设计用于跟踪各种产品的数据库。它的行看起来像这样:
ProductName |年|价格|保证金|好的成本|利润|
我正在设计网格。目前,该观点如下。 ProductName是新的,目前尚未考虑。
------------------------ ------------------------------
第1年第2年3年级4
价格
保证金
成本好
利润
---------- ---------------------------------------------
假设我有两种产品与ProductName不同。我想创建一个查询,允许我生成一个如下所示的网格:
--------------- --------------------------------------------
第1年第2年第3年第4年
价格(产品1)
价格(产品2)
保证金(产品1)
保证金(产品) 2)
成本(产品1)
成本(产品2)
利润(产品1)
利润(产品2)
-------------------------------------------- ----------
任何人都可以通过SQL查询来帮助我生成像这样的交替数据product?
听起来你正试图使用数据透视表结果。
请看以下内容链接
在SQL查询中使用Pivot的简单方法 [ ^ ]
Hey all!
I have a database I designed to track various products. Its rows look something like this:
ProductName | Year | Price | Margin | Cost of Good | Profit |
I am designing a grid. Currently, the view is as follows. ProductName is new and not currently taken into account.
------------------------------------------------------
Year 1 Year 2 Year 3 Year 4
Price
Margin
Cost of Good
Profit
-------------------------------------------------------
Let's say I have two products differentiated by ProductName. I would like to create a query which allows me to produce a grid that looks like this:
-----------------------------------------------------------
Year 1 Year 2 Year 3 Year 4
Price (Product 1)
Price (Product 2)
Margin (Product 1)
Margin (Product 2)
Cost of Good (Product 1)
Cost of Good (Product 2)
Profit (Product 1)
Profit (Product 2)
------------------------------------------------------
Can anyone help me with the SQL query to produce the data alternating like this by product?
Sounds like you are trying to use a pivot table result.
see the following link
Simple Way To Use Pivot In SQL Query[^]
这篇关于SQL(按产品交替排)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!