Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Table download last page: http://www.boltfile.com/download/c11e6497I should create 1 view that display both the 5 best sales persons (highest bonus) and after that the 5 sales persons that have sold most las month. it´s displayed in table bokning colum tidpunkt (date).I have to do this in just 1 view.Bonus i calculated provision * provisionsandel and should be displayed by person. You can an example on "uppgift 3" in the .pdf file.Thanks all foe help, I really cant understand what to do.
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2008-07-06 : 21:10:28
Please post the expected result of the view requiredKH[spoiler]Time is always against us[/spoiler]
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-07-07 : 00:06:37
something like:-
SELECT * FROM(SELECT TOP 5 Person,SUM(provision * provisionsandel ) AS Bonus,'Highest Bonus' AS CategoryFROM YourTableGROUP BY PersonORDER BY Bonus DESC)tUNION ALLSELECT *FROM(SELECT TOP 5 Person,SUM(salescalculationhere) AS Sales,'Highest Sales' AS CategoryFROM YourTableGROUP BY PersonORDER BY Sales DESC)t1
please provide more info if you need more precise soln.
aikman
Starting Member
22 Posts
Posted - 2008-07-07 : 03:06:19
Example on how it could look like:SELECT * from “my View”Type quantity/commission salesID SalesPersonProvision 1584 36 Sandra KarssonProvision 1453 30 Zoe BaumProvision 1354 38 Zula LovejoyProvision 1264 22 Soo MendozaProvision 1034 18 Sonja SchreckQuantity Customers 66 30 Zoe BaumQuantity Customers 63 19 Ceola RockettQuantity Customers 63 6 Esbjorn AdamssonQuantity Customers 61 13 Maria AhlgrenQuantity Customers 60 10 Ronda Brann(10 row(s) affected)
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-07-07 : 03:40:39
Bonus i calculated provision * provisionsandelwhats the field for provisionsandel?
aikman
Starting Member
22 Posts
Posted - 2008-07-07 : 04:12:36
Table bokningbokning_id produkt_id saljare_id kund_id tidpunkt1 8 13 895 2005-10-09 00:00:00.0002 2 5 40 2005-11-12 00:00:00.0003 5 22 364 2005-10-31 00:00:00.0004 2 2 5 2006-04-22 00:00:00.0005 10 15 429 2006-03-23 00:00:00.0006 6 18 209 2005-10-05 00:00:00.0007 6 15 476 2006-04-10 00:00:00.0008 7 7 233 2005-12-18 00:00:00.0009 10 38 79 2006-03-05 00:00:00.000Table productprodukt_id namn provision1 42" Plasma TV 10002 Nokia 6150 5003 Telefonabonnemang 1004 19" LCD skärm 5005 EU moped 3000Table lonekatlonekat_id beskrivning manadslon provisionsandel1 Ingångslön 10000 0.102 Junior säljare 15000 0.403 Säljare 20000 0.604 Senior säljare 25000 0.80table personalpers_id chef_id lönekategori förnamn efternamn Titel1 34 1 Johan Forsberg Säljare 2 35 1 Carl Johnson Säljare 3 29 1 Erik Persson Säljare 4 30 1 Jonas Svegerud Säljare 5 31 1 Petter Solberg Säljare 6 32 1 Esbjörn Adamnsson Säljare 7 33 1 Lorriane Barksdale Säljare 8 34 2 Johannes Agerberg Säljare 9 35 2 Christoffer Andersson Säljare 10 29 2 Peter Svensson Säljare 11 30 2 Tobias Petterson Säljare 12 31 2 Sofia Nilsson Säljare 13 32 2 Maria Ahlgren Säljare To calculate Bonus you have to look what they have sold in table bokning.produkt_id (every row is one sold unit), and in table produkt colum provision shows how much every product has in commission. Then in table lonekat colum provisionsandel shows the percent % that the employee get in from the total commission that he has sold for.I´ll hope you understand now, i know i don´t :S