A database problem Daily (1)

topic

CREATE FUNCTION BOOK_PROFIT(@year int)
RETURNS @tb_book_profit TABLE(书号 varchar(50), 销售总额 int)
AS
BEGIN
INSERT INTO @tb_book_profit
(
	SELECT 书号, SUM(单价*销售数量) AS 销售总额
	FROM 销售表 X JOIN 图书表 T
	ON X.书号 = T.书号
	WHERE X.销售时间 = @year
	GROUP BY X.书号#2书号	
)
RETURN#1
END	

Practical operation:

  1. Plus RETURN
  2. ISBN designated as X table
CREATE FUNCTION DBO.BOOK_PROFIT(@year int)
RETURNS @tb_book_profit TABLE(书号 varchar(50), 销售总额 int)
AS
BEGIN
INSERT  @tb_book_profit

	SELECT x.no as 书号, SUM(cost*quantity) AS 销售总额
	FROM sell X JOIN commodity T
	ON X.no = T.no
	WHERE X.time = @year
	GROUP BY X.no

RETURN 
END	

SELECT * FROM DBO.BOOK_PROFIT(11) RESULT
GO

The use of SQL SERVER and self-built performance practice:
Here Insert Picture Description
Self-built table

Published 39 original articles · won praise 3 · Views 4656

Guess you like

Origin blog.csdn.net/cascara/article/details/104255984