小编Cer*_*eal的帖子

带除法的 SQL“WHERE”

因此,我想要获得产品评级并应用它来获得顶级产品。

    CREATE PROCEDURE [dbo].[TopProducts]

AS
BEGIN
    SELECT Prod_Name, Qty, ProductImage, Price, Store_Name
    FROM Product P, Store S
    WHERE ....
Run Code Online (Sandbox Code Playgroud)

在我的产品表中,您可以找到:

(
Prod_ID int not null IDENTITY(1,1),
Store_ID int not null,
Price int not null ,
Prod_Name varchar(50) not null,
Qty int not null,
ProductDescription varchar(50),
RatingSum int not null,
RatingCount int not null,
ProductImage varchar(50),
Prod_Date date,
PRIMARY KEY (Prod_ID),
FOREIGN KEY (Store_ID) REFERENCES Store(Store_ID)
);
Run Code Online (Sandbox Code Playgroud)

所以,我想放入“WHERE”条件,例如:(RatingSum/RatingCount) >= 4 ...。

我该怎么做?

编辑:为了避免混淆!评级总和,将是一个整数,其中评论者的全部评级将相互相加,而评级计数是每次用户评论该特定产品(此 Prod_ID)时都会增加的东西,在此之后,评级就是您得到的从这个除以那个!

有没有更好的方法来获取多个评论者对特定产品的平均评分?

database sql-server where-clause

1
推荐指数
1
解决办法
4364
查看次数

标签 统计

database ×1

sql-server ×1

where-clause ×1