我如何从数据库中选择十大明智的产品销售 [英] how can i select top 10 product wise sale from database

查看:70
本文介绍了我如何从数据库中选择十大明智的产品销售的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的数据库中选择十大产品.
我想代表我的查询设计水晶报表.
我的员工需要本月销售的十大产品.
但我不知道该怎么找到.
\ plz帮助我

i want to select top 10 product from my database.
i want to design crystal report on the behalf of my this query.
my employ need top 10 product which sale in current month.
but i dont know how can i find.
\plz help out me

推荐答案

它不是那么简单:
It''s not as simple as that:
SELECT TOP 10 * FROM myTable

将返回表中的前十项,但只有您才能决定是什么使它们成为您想要的.您可能需要WHERE 子句(以确保月份正确)和ORDER BY子句(以正确地组织它们)的组合.
但是只有您知道什么使产品成为十佳".它是单位数量吗?总价值?每个销售员的单位?还是什么.

在SQL Server Managment Studio中尝试一下.看看你得到什么...

Will return you the first ten items in the table, but only you can decide what makes them the ones you want. You probably want some combination of WHERE clause (to ensure that the month is correct) and ORDER BY clause (to organise them properly).

But only you know what makes a product "top ten". Is it number of units? Total value? Units per salesman? Or what.

Try it in SQL Server Managment Studio. and see what you get...


CREATE PROCEDURE spTopProducts	
AS
BEGIN
	
	SET NOCOUNT ON;
	
	select top 10 SUM(issue_qty) issue_qty,itmcode into #temp
	from tblSales 
	group by itmcode
	order by 1
	
	select *
	from tblProducts
	where itemcode in (select itemcode from #temp)
	

END



这应该会有所帮助,我的假设是

*排名前10位的产品基于销量
*您有一个单独的表,其中包含要为报告检索的产品?



This should help and my assumptions are

* Top 10 products are based on the volume sold
* You have a seperate table for products which you want to retrieve for the reporting ?


这篇关于我如何从数据库中选择十大明智的产品销售的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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