如何获得哪些产品价格逐年上涨 [英] how to get which product price is increase year by year
问题描述
您好我在sql server中有一个疑问。如何获取 哪个产品名称 价格逐年上涨。下表中的
苹果产品价格逐年上涨,所以如果任何一年的产品价格高而另一年我需要的记录为
价格下降然后无需获得该记录
如果有任何产品,则需要
一年的价格是10,明年的价格必须比prviouse增加,然后该记录需要显示
CREATE TABLE [dbo]。[product](
[pid] [int] NULL,
[price] [money] ] NULL,
[年] [int] NULL
)
CREATE TABLE [dbo]。[productdetails](
[pid] [int] NULL,
[pname] [varchar](50)NULL
)
INSERT [ dbo]。[product]([pid],[price],[year])VALUES(1,1.0000,2010)
GO
INSERT [dbo]。[产品]([pid],[price],[year])VALUES(1,9000000,2011)
GO
INSERT [dbo]。[product]([ pid],[price],[year])VALUES(1,13.0000,2012)
GO
INSERT [dbo]。[product]([pid],[价格],[年])价值(2,30.0000,2010)
GO
INSERT [dbo]。[product]([pid], [价格],[年])价值(2,20.0000,2011)
GO
INSERT [dbo]。[product]([pid],[price], [年])VALUES(2,19.0000,2012)
GO
INSERT [dbo]。[product]([pid],[price],[year]) VALUES(3,8.00万,2010)
GO
INSERT [dbo]。[product]([pid],[price],[year])VALUES(3, 10.0000,2011)
GO
INSERT [dbo]。[product]([pid],[price],[year])VALUES(3,15.0000,2012)
GO
INSERT [dbo]。[productdetails]([pid],[pname])VALUES(1,N'lg')
GO¥
INSERT [dbo]。[productdetails]([pid],[pname])VALUES(2,N'samsung')
GO¥ b $ b INSERT [dbo]。[productdetails]([pid],[pname])VALUES(3,N'apple')
GO
INSERT [dbo] 。[productdetails]([pid],[pname])VALUES(4,N'mi')
基于以上数据,我想要输出如下
产品名称
Apple
$
我尝试如下
选择*来自产品p 加入产品pd on p.pid = pd.pid
和p.year = pd.year + 1和
p.price> = pd.price你可以告诉我如何在sql server中编写查询以执行此任务
Hi I have one doubt in sql server .how to get which productname have price increaseing year by year.
in the below table apple prodct price is increase year by year so I need that records
if any product one year is high and another year price is drop then no need to get that records
if any product one year price is 10 and next year price must be increast compare to prviouse then that record need to display
CREATE TABLE [dbo].[product](
[pid] [int] NULL,
[price] [money] NULL,
[year] [int] NULL
)
CREATE TABLE [dbo].[productdetails](
[pid] [int] NULL,
[pname] [varchar](50) NULL
)
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (1, 10.0000, 2010)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (1, 9.0000, 2011)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (1, 13.0000, 2012)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (2, 30.0000, 2010)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (2, 20.0000, 2011)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (2, 19.0000, 2012)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (3, 8.0000, 2010)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (3, 10.0000, 2011)
GO
INSERT [dbo].[product] ([pid], [price], [year]) VALUES (3, 15.0000, 2012)
GO
INSERT [dbo].[productdetails] ([pid], [pname]) VALUES (1, N'lg')
GO
INSERT [dbo].[productdetails] ([pid], [pname]) VALUES (2, N'samsung')
GO
INSERT [dbo].[productdetails] ([pid], [pname]) VALUES (3, N'apple')
GO
INSERT [dbo].[productdetails] ([pid], [pname]) VALUES (4, N'mi')
Based on above data I want output like below
Productname
Apple
I tried like below
select * from product p join product pd on p.pid=pd.pid
and p.year=pd.year+1 and
p.price >=pd.price
can you please tell me how to write query to achive this task in sql server
推荐答案
请不要将相同的问题发布到
多个论坛。这样做会浪费别人的时间和精力。这些是最终用户支持的论坛,人们无需支付费用就坐在电脑旁,并尽可能快地回答问题。
Please do not post the same question to multiple forums. You waste the time and efforts of others when doing so. These are end-user supported forums and people are not paid to sit at the computer and answer questions as quickly as you can post them.
这篇关于如何获得哪些产品价格逐年上涨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!