Top 100 Items Sold In The Last 60 Days Rank Tracking
Apr 14, 2006
I want to be able to track my top 100 items sold in the last 60 days. Each night I want to calculate it then compare it with the numbers from the previous night. Then show both ranks. My problem is assigning them ranks. Bascily I have a view that shows the top 200 sorted correctly. I am thinking creating a DTS to make a new table with adding transformations. But I am not sure how to code the Visial Basic. Below is what I thought it would be, but it doesn't work. Get a generic error. Any ideas?
dim ranknum
ranknum = 0
Function Main()
ranknum += 1
DTSDestination("Rank") = ranknum
DTSDestination("ItemNumber") = DTSSource("ItemNumber")
DTSDestination("QtySold") = DTSSource("QtySold")
Main = DTSTransformStat_OK
End Function
View 2 Replies
ADVERTISEMENT
Jun 3, 2014
I am looking for a way to show how I can have a result set that shows a record with one item and the number of records where it was purchased or sold. Below is my sample data.
Use tempdb
go
create table #ItemLedgerEntry
(
ENTRYNO INT NOT NULL
, ITEMNO VARCHAR (50) NOT NULL
, POSTINGDATE DATETIME NOT NULL
, ENTRYTYPE INT NOT NULL
[code]....
I know something like this will give me results but I'd like to run one query.
select itemno, count(*) from #ItemLedgerEntry where entrytype = 0
group by itemno
order by count(*) desc
View 5 Replies
View Related
Feb 28, 2008
Hello,
I'm hoping someone can help me out with this. In order to add an sequence dimension in an ssas cube, I need to rank chronological item in a t-sql data set in order of their distinct appearance. I've tried to do this in mdx and there's just no easy way. I've also tried various ways in t-sql to achive, includeing ranking functions, custom udf, etc. To no avail.
The original dataset would look like this.
date, member_id, action
1/1/2008, 123, register
1/2/2008, 123, create_item_a
1/3/2008, 123, create_item_b
1/4/2008, 123, create_item_a
1/5/2008, 123, create_item_c
1/6/2008, 123, create_item_b
I need another column that flags the action in order of appearance, like so
date, member_id, action, appearance_rank
1/1/2008, 123, register, 1
1/2/2008, 123, create_item_a, 2
1/3/2008, 123, create_item_b, 3
1/4/2008, 123, create_item_a,2
1/5/2008, 123, create_item_c,4
1/6/2008, 123, create_item_b,3
So the "register" action would be the first thing a user did, "create_item_a" the second, create_item_b the third. However, the next occurrance of create_item_a would still retain the rank of 2 as it's not a new action for this user. The ranks would be unique to the actions, based on the first time they occurred.
This has been perplexing, but I feel like there is simple way to do this using some of the ranking functions, but just haven't been able to get it figure out.
Any help would be appreciated.
Regards...
View 5 Replies
View Related
May 24, 2015
Working on sqlserver 2008 R2
CREATE TABLE OrderRanking
(
OrderID INT IDENTITY(1,1) NOT NULL,
CustomerID INT,
OrderDate date
)
INSERT OrderRanking (CustomerID, OrderDate)
[Code] ...
Looks fine but what I need is DRP with this:
CustomerID OrderDate 'DRP taking care of the gap in the days'
1 '01-01-2015' 1
1 '01-01-2015' 1
2 '02-01-2015' 1
2 '02-01-2015' 1
2 '05-01-2015' 4
2 '05-01-2015' 4
View 2 Replies
View Related
Oct 7, 2004
I'm using DataList to return vales stored in an SQL database, of which one of the fields contains the date the record was added.
I am trying to fill the dataset with items only from the last 30 days.
I've tried a few different ways, but all the database rows are returned.
What is the WHERE clause I sholud use to do this??
Thanks
View 2 Replies
View Related
Sep 13, 2013
I need to run a query on all of the items in the product table where the amount that I've sold over the past 2 days is greater than the amount I have available. Basically, am I likely to sell out of stock?
I have all of the information I need across 3 tables:
- bvc_product
- bvc_order
- bvc_orderitem
The database is available here: [URL] .... It's about 400 KB zipped & 3 MB unzipped.
I've written the following query & I can see all of the data that I need, but (even conceptually) I don't know how to make the comparison.
SELECT
o.[ID]
,o.[TimeOfOrder]
,oi.[Qty]
,p.[ID]
,p.[AggregateQty]
FROM [tmpDB].[dbo].[bvc_Order] o
INNER JOIN tmpDB.dbo.bvc_OrderItem oi
ON o.ID = oi.OrderID
INNER JOIN tmpDB.dbo.bvc_Product p
ON p.ID = oi.ProductID
I use Microsoft SQL 2008
View 16 Replies
View Related
Jul 14, 2015
I have a code I wrote and I'm required to get Product Name and Quantity with the maximum quantity sold per day. My issue is with the "per day" part, here's my code below.
SELECT
t.SalesOrder
,t.OrderQuantity
,t.OrderTotal
,t.OrderDate
,p.ProductName
FROM Transactions t
INNER JOIN SalesPerson sp
ON t.SalesPersonID = sp.SalesPersonID
INNER JOIN Product p
ON t.ProductID = p.ProductID
WHERE sp.SalesPersonName LIKE 'John%'
Now from this code I need to get only Product Name and Quantity with the maximum quantity sold per day, here's what I tried;
SELECT
SUM(t.OrderQuantity) AS Order_Quantity
,p.ProductName
FROM Transactions t
INNER JOIN Product p
ON t.ProductID = p.ProductID
WHERE sp.SalesPersonName LIKE 'John%'
GROUP BY p.ProductName, t.OrderQuantity
HAVING MAX(t.OrderQuantity)
View 2 Replies
View Related
Apr 17, 2007
Hi: I'm try to create a stored procedure where I sum the amounts in an invoice and then store that summed amount in the Invoice record. My attempts at this have been me with the error "The multi-part identifier "items.TAX" could not be bound"Any help at correcting my procedure would be greatly appreciate. Regards,Roger Swetnam ALTER PROCEDURE [dbo].[UpdateInvoiceSummary] @Invoice_ID intAS DECLARE @Amount intBEGIN SELECT Invoice_ID, SUM(Rate * Quantity) AS Amount, SUM(PST) AS TAX FROM InvoiceItems AS items GROUP BY Invoice_ID HAVING (Invoice_ID = @Invoice_ID) Update Invoices SET Amount = items.Amount WHERE Invoice_ID =@Invoice_IDEND
View 3 Replies
View Related
Feb 25, 2015
I am struggling to come up with a set-based solution for this problem (i.e. that doesn't involve loops/cursors) ..A table contains items (identified by an ItemCode) and the set they belong to (identified by a SetId). Here is some sample data:
SetIdItemCode
1A
1B
24
28
26
310
312
410
[code]....
You can see that there are some sets that have the same members:
- 1 and 10
- 2 and 11
- 7, 8 & 9
What I want to do is identify the sets that have the same members, by giving them the same ID in another column called UniqueSetId.
View 8 Replies
View Related
Apr 10, 2015
I'm having an issue creating a report that can group & sum similar items together (I know in some ways, the requirement doesn't make sense, but it's what the client wants).
I have a table of items (i.e. products). Â In some cases, items can be components of another item (called "Kits"). Â In this scenario, we consider the kit itself, the "parent item" and the components within the kit are called "child items". Â In our Items table, we have a field called "Parent_Item_Id". Â Records for Child Items contain the Item Id of the parent. Â So a sample of my database would be the following:
ItemId | Parent_Item_Id | Name | QuantityAvailable
----------------------------------------
1 | NULL | Kit A | 10
2 | 1 | Item 1 | 2
3 | 1 | Item 2 | 3
4 | NULL | Kit B | 4
5 | 4 | Item 3 | 21
6 | NULL | Item 4 | 100
Item's 2 & 3 are child items of "Kit A", Item 5 is a child item of "Kit B" and Item 6 is just a stand alone item.
So, in my report, the client wants to see the SUM of both the kit & its components in a single line, grouped by the parent item. Â So an example of the report would be the following:
Name | Available Qty
--------------------------
Kit A | 15
Kit B | 25
Item 4 | 100
How I can setup my report to group properly?
View 6 Replies
View Related
Jan 7, 2014
I have an SQL code below which removes weekends and non working days when calculating days difference between two dates:
ce.enquiry_time represents when the enquiry was logged
(DATEDIFF(dd, ce.enquiry_time, getdate()) + 1)
-(DATEDIFF(wk, ce.enquiry_time, getdate()) * 2)
-(CASE WHEN DATENAME(dw, ce.enquiry_time) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, getdate()) = 'Saturday' THEN 1 ELSE 0 END)
-(SELECT COUNT(*) FROM nonworking_day WHERE nonworking_day.nonworking_date >= ce.enquiry_time AND nonworking_day.nonworking_date < dateadd(dd,datediff(dd,0,getdate()),1))
It works but I don't understand how it works it out. I am having issues understanding each coloured piece of code and how it works together.
View 1 Replies
View Related
Oct 25, 2006
Hello,I am writing a query to select records added to a table today, in the last 3 days, in the last 7 days, and so on.Here is what I have (which seems that its not working exactly). -- total listed today
SELECT COUNT (*) FROM mytable WHERE DATEDIFF(Day, mydatecolumn, getdate() ) <= 0-- total listed yesterday
SELECT COUNT (*) FROM mytable WHERE DATEDIFF(Day, mydatecolumn, getdate() ) <= 1-- total listed in the last 3 days
SELECT COUNT (*) FROM mytable WHERE DATEDIFF(Day, mydatecolumn, getdate() ) <= 3I'd like to be able to select the count for records added within the last X number of days. Can someone please help me out? Thanks so much in advance.
View 1 Replies
View Related
May 12, 2006
I cannot find an easy way to DELETE items which are > 1 time in my table (i am working with MS SQL 2000)
idserialisOk
-------------------
2AAA1
3BBB0
5dfds0
6CCC1
7fdfd 0
8AAA0
9CCC0
I want to DELETE each Row IN
SELECT doublons.serial, Count(doublons.serial) AS 2Times
FROM doublons
GROUP BY doublons.serial
HAVING Count(doublons.serial)>1
and WHERE isOK = 0
in my exemple , after deleting, my table must look like
idserialisOk
-------------------
8AAA1
9CCC1
3BBB0
5dfds0
7fdfd0
thank you for helping
View 10 Replies
View Related
Jun 30, 2006
Hi,
Why adidas is better-ranked than nike??
Table "indice":
idcCod fabCod mcaCod catCod fabNom mcaNom catNom
1111NikeNikeRopa
2221AdidasAdidasRopa
3113NikeNikeMedias
4118NikeNikeLargas
SELECT[RANK] ,[KEY],idc.*
FROMFREETEXTTABL (dbo.indice,mcaNombre,fabNombre,catNombre),
'ropa adidas nike',
LANGUAGE 3082, 5) res left join
dbo.indice idc with (nolock) on idc.idcCodigo=res.[key]
ORDER BY [RANK] DESC;
Result:
RANK KEY
182
03
04
01
Why idcCods's 1 and 2 have different rank??
because idcCod's 3 and 4 affects ?? or it's just thinks of language??
Thank's in advance
View 5 Replies
View Related
Oct 14, 2005
Ok. Im not able to understand this logic please help. As you can see we have 2 columns of ranks, 1)normal 2)corrective. what is the logic behind this and how do u write a query for this? these ranks are for the Salary Column.
Imran,
"You truly do not know someone untill you fight them."-THE MATRIX.
EmpID Empname EmpSalary RankNormal RankCorrective
1 A 150001 1
2 B 100002 4
3 C 150001 1
4 D 40003 5
5 E 150001 1
6 F 15004 6
7 G 15004 6
8 H 5005 8
View 20 Replies
View Related
Aug 17, 2006
I have table :
Result1 Rank
5
6
78
4
27
3
How to rank in above table ?
Thank you very much !
View 13 Replies
View Related
May 28, 2007
Hi All,
Please let me know the equivalent of RANK() over ( order by...)
in SQL server 2000.
I thought this was supported in SQL server 2000.
Please let me know if there exists a user defined function.
Thanks in Advance.
Thanks
View 1 Replies
View Related
Jun 28, 2006
I would like to write a query that gives me the values of a set ofobservations, and their rank.CREATE TABLE #Values(val int)INSERT #Values SELECT 1INSERT #Values SELECT 5INSERT #Values SELECT 10I would like to select this:1 10 -- rank 1, value 102 53 1I can put them into a temp table with an identity column, ordered bythe column I'm interested in, and then retrieve in order by theidentity column. I'm wondering if there's a way to do that with asubquery.Thanks,Jim
View 3 Replies
View Related
May 22, 2006
I've written a bunch of code using contains for fts. Then as I was trying to run the sorting, I realized that I have to use containstable in order to sort by rank. Is that correct? When I was using contains, I just used it as a where clause so I would have something like...
WHERE ((PostedUntil >= '5/22/2006') AND (SiteId=199)) AND (CONTAINS (PositionTitle, '"sales"') OR CONTAINS (Description, '"sales"'))
From the examples I've seen, in order to use containstable, I have to join a new dynamic table to the freetext enabled table and it only uses 1 containstable phrase for the new table. In my case, I may have multiple containstable phrases, so would they all fall in a () set like..
FROM Categories AS FT_TBL INNER JOIN
(CONTAINSTABLE (table, col1, searchphrase) OR (CONTAINSTABLE(table, col2, searchphrase2) OR CONTAINSTABLE (table, col3, searchphrase3)) AS KEY_TBL
... or would each containstable have to be a new join? I don't want to spend anymore time going back and rewriting code just to test it since it's about a days worth of recoding. Thanks.
View 3 Replies
View Related
May 13, 2008
ive created a photo sharing site, and im trying to show the statisics for certain users, so far i can COUNT all the photos the user has upload, and show them in descending order, but i need to be able to see the ranking of the user, like :
RANK USERID No. Of Photos
1 10 100
2 8 70
3 9 85
is there anyway of doing this? thanks Si!
View 7 Replies
View Related
Aug 1, 2006
My data:
Code:
CUST NO | StoreName| Rank
Cust1 0781 1
Cust1 0246 2
Cust1 0481 3
Cust2 2101 1
Cust2 8876 2
Cust2 5445 3
Cust3 3243 1
Cust3 4545 2
Cust3 3223 3
Im trying to find a way to rank as shown in the third column.
This is the code im using:
Code:
SELECT top 100 (CustomerNo)as CustomerNo, StoreName,
(SELECT COUNT(DISTINCT CustomerNo)
FROM dbo.Top3CustomerNoStores AS O2
WHERE O2.CustomerNo < O1.CustomerNo) + 1 AS drnk
FROM Top3CustomerNoStores as O1
... and getting this result
Code:
CUST NO | StoreName| drnk
Cust1 0781 1
Cust1 0246 1
Cust1 0481 1
Cust2 2101 2
Cust2 8876 2
Cust2 5445 2
Cust3 3243 3
Cust3 4545 3
Cust3 3223 3
... and using this code
Code:
SELECT top 100 (CustomerNo)as CustomerNo, StoreName,
(SELECT COUNT(*)
FROM dbo.Orders AS O2
WHERE O2.qty < O1.qty) + 1 AS rnk
.... which gives me ...
Code:
CUST NO | StoreName| rnk
Cust1 0781 1
Cust1 0246 1
Cust1 0481 1
Cust2 2101 4
Cust2 8876 4
Cust2 5445 4
Cust3 3243 7
Cust3 4545 7
Cust3 3223 7
I have noticed in SQL 2005, this is accomplished much easier with built in functions.
any help appreciated
View 1 Replies
View Related
Jun 7, 2006
Hi all,
until recently ive been using a rank equation to calculate rank,
essentially doing a select statement and selecting this as the rank field, where query 2 is the same as query 1:
((select count(*) from (query1) where (query1).value < (query2).value) +1)) as Rank
problem is that this is now running like a dog (takes 10 secs) and i'd like to try and do this another way- 2005 has a rank function, how can i do this in 2000?
here is the full statement :
SELECT StudentId, GCSE_Score, LTRIM(STR
((SELECT COUNT(*)
FROM dbo.[Score2004-05]
WHERE GCSE_score < s.GCSE_Score) + 1)) AS GCSE_Rank, SetId
FROM dbo.[Score2004-05] S
WHERE (SetId = '2004/2005')
greg
View 4 Replies
View Related
Jan 8, 2008
Is there a way to use the Rank function like in 2005 for sql 2000
View 6 Replies
View Related
Apr 8, 2008
I need help in understanding how the rank is calculated in FREETEXTABLE. I have a following query
select ft_tbl.saon
,ft_tbl.paon
,ft_tbl.street
,ft_tbl.postcode
,key_tbl.rank
from temp as ft_tbl
INNER JOIN freetextTABLE(temp, (saon, paon, street), '80 ridge avenue', 15) as key_tbl
ON FT_tbl.ID = key_tbl.[key]
First, the resulting rows does have one record which has an address 80 ridge avenue but it appears at 15th place. Ideally it should appear on 1st. All the ranks of the results are same.
Second, the results are also showing two rows which does not contain the specified search string at all. They not only appears above in the resulting table but also have the same rank as the result in question (80 ridge avenue). For example result shows €œLong Ridges, Flat 21, Fortis Green€? at fifth place which is no way near the search string. And actual record shows up at 15th Place
Is there any way we can influence the rank to show exact match first. Just to clarify I have removed the digits from noise file as we need to search house numbers. Digits appears in noise file as default.
View 1 Replies
View Related
Jul 30, 2007
Hi ,
I have a report created and within the report is columns that perform additions on the fields from the database.
I want to create a rank column to show the rank of the row compare with the rest.
Col1 Col2 Total Ranks
1 2 3 3
2 3 5 1
2 2 4 2
On the above Col 1 and 2 would come form my database, Total is calculated by the report. How can I get ranking on this total? I cannot sort by the total as the report should only showing rankings but not be ordered by the rank.
I am using SQL Server 2005 Reporting Services...anny help is much appreciated.
Thanks
View 8 Replies
View Related
Mar 15, 2008
This query:
SELECT xx.JumpHeight, xx.HeightRank, xx.NoEvents, xx.MinRunDate, xx.DogIdent,
Dogs.CallName, DogOwner.LastName, DogOwner.FirstName
FROM
(SELECT JumpHeight, DogIdent, MIN(RunDate) as "MinRunDate", COUNT(Event_ID) AS "NoEvents",
RANK() OVER (PARTITION BY JumpHeight ORDER BY COUNT(Event_ID) DESC, MIN(RunDate)) AS "HeightRank"
FROM EventData
WHERE Event=@Event
GROUP BY JumpHeight, DogIdent) AS xx, Dogs, DogOwner
WHERE (Dogs.Breed = @Breed AND xx.DogIdent = Dogs.DogIdent and Dogs.Owner_ID = DogOwner.Owner_ID) AND
(xx.HeightRank <= 10)
ORDER BY xx.JumpHeight, xx.HeightRank
produces this output:
Jump Ht.
Rank
# of Events
First Event
Owner
Call Name
08
3
1
2/19/2006
Some Owner
Otto
08
4
1
3/12/2006
Some Owner
Schotzie
I want it to produce this output:
Jump Ht.
Rank
# of Events
First Event
Owner
Call Name
08
1
1
2/19/2006
Some Owner
Otto
08
2
1
3/12/2006
Some Owner
Schotzie
I have tried several things and cannot correct the problem. Obviously, RANK is being evaluated in the wrong place, but placing it elsewhere has failed to produce the above results.
I appreciate any help I can get. Thanks!
View 4 Replies
View Related
Dec 20, 2007
Hi,All,
I have one table like this
UserID,Name,GameScore
1 A 25
2 B 23
3 C 22
4 D 25
5 E 23
6 F 26
Now i want the query which return like this
Name Score Rank
F 26 1
A 25 2
D 25 2
B 23 3
E 23 3
C 22 4
Can anyone give me the sql 2000 query for this
View 4 Replies
View Related
Mar 16, 2005
Hi all:
In the Sql below, sample from William Pearson, the amount Spend is in descending order and the Rank number is in ascending order. Like this:
Spend Rank
24 1
12 2
10 3
9 4
What I wish to accomplish is:
Spend Rank (descending)
24 4
12 3
10 2
9 1
Please let me know what I need to accomplish it.
Thanks for the help
Victor
SELECT
CompanyName, Spend,
(SELECT COUNT(*)
FROM
ACC0704 AS CoSpendTotal
WHERE
ACC0704.Spend <= CoSpendTotal.Spend)
AS Rank
FROM
ACC0704
ORDER BY
Spend DESC
View 7 Replies
View Related
Feb 8, 2006
Hi,
i want to create a report so that a list of the top 30 records are returned to the report user. In the report i want to have the records position in the list shown (ie the first row should have 1. and the second should be 2. right on down to the 30th having 30.)
how do i achieve this please?
many thanks
FatherJack
View 1 Replies
View Related
Nov 23, 2007
Hi all,
I don't know how to explain what I wanna do in english so here's a concrete example:
I have this data
Item - Qty
IT1 - 2
IT2 - 2
IT1 - 4
IT1 - 5
IT2 - 2
And I wanna do something like this
Item - Rank - Qty
IT1 - 1 - 2
IT1 - 2 - 4
IT1 - 3 - 5
IT2 - 1 - 2
IT2 - 2 - 2
So basically I want to assing a rank (on the fly) in a SELECT statement
Thanks in advance
Or Tho
View 10 Replies
View Related
Aug 1, 2012
i am trying to create a rank formula.i just need to return the highest MCC count for the mcc code and return the seller code...So eg row 3 and 4, there are two MMC CODE called 4772, i need the formula to return the seller code r10, this is because r10 has 9 counts against that mcc code, and r03 has 9,
View 2 Replies
View Related
Feb 27, 2004
Using FoodMart, how can i add time to this:
WITH MEMBER [Measures].[Rank] AS 'Rank ( Product.CurrentMember,Order( {Product.CurrentMember.Parent.Children} ,[Profit], DESC) ) '
SELECT
{[Profit] , [Rank]} ON COLUMNS,
Drink.Children ON ROWS
FROM Sales
View 2 Replies
View Related
Apr 16, 2014
I need to get the previous price for all my PROMOTION records but not when the previous record is a type PROMOTION also it needs to keep going back to get the price.
I have created a table with RANK in which works OK to get previous price for all but how can I say if previous price is type PROMOTION go to next previous prices...
Bets way to show an example is with a jpeg image I have but having trouble inserting into this message...
SELECT a.[StartPrice]
,a.[ProductID]
,a.[Colour]
,ISNULL(b.[Price],a.[Price]) AS [Price Before]
,a.[Price] AS [Promotion Price]
[Code] ...
Table
PriceCodeStartPriceEndPriceProductIDColourPriceRank
RETAIL21-Oct-1324-Dec-13Bike15BLUE39.001
PROMOTION29-Nov-1301-Dec-13Bike15BLUE31.202
PROMOTION12-Dec-1323-Dec-13Bike15BLUE31.203
MARKDOWN25-Dec-1314-Jan-14Bike15BLUE31.204
[Code] ....
Want I'm trying to do select PriceCode PROMOTION and get previous price:
Get previous price
PROMOTION29-Nov-1301-Dec-13Wheel1BLACK31.2039.00
But in this example it picks up the PROMOTION before and I need to ignore this and get rank 1 price for both
PROMOTION29-Nov-1301-Dec-13Bike15BLUE31.2039.00
PROMOTION12-Dec-1323-Dec-13Bike15BLUE31.2039.00
View 8 Replies
View Related