If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Re-construct 4 tables into 1 table and sort Fraction value [Question]

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-12, 08:54
newtechhk newtechhk is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
Question Re-construct 4 tables into 1 table and sort Fraction value [Question]

Bet Table:
BetId, int
BetName, nvarchar
BettypeId, int

Bettype Table:
BettypeId, int
BettypeName, nvarchar

BookMaker Table:
BookMakerId, int
BookMakerName, nvarchar
SortOrder, int

Odds Table:
OddsId, int
BookMakerId, int
BettypeId, int
BetId, int
MatchId, int
FixtureId, int
OddsValue, nvarchar (e.g. 31/11, it is a fraction)

SQL:
SELECT COUNT(BetId) FROM [Bet] where BettypeId = 1
It can count how many Bet under a Bet type.
Result: 3

SELECT * FROM [odds] where MatchId=116 and BettypeId = 1 and
BetId in (SELECT BetId FROM [Bet] where BettypeId = 1)
order by BookMakerid, BetId
Result:
2355 1 1 1 116 116 11
2333 1 1 2 116 116 9/2
2311 1 1 3 116 116 1/4
2356 2 1 1 116 116 11
2334 2 1 2 116 116 9/2
2312 2 1 3 116 116 1/4
2357 3 1 1 116 116 9
2335 3 1 2 116 116 9/2
2313 3 1 3 116 116 2/7
2358 4 1 1 116 116 8
2336 4 1 2 116 116 9/2
2314 4 1 3 116 116 1/4
2359 5 1 1 116 116 9
2337 5 1 2 116 116 9/2
2315 5 1 3 116 116 2/7
2360 6 1 1 116 116 9
2338 6 1 2 116 116 19/4
2316 6 1 3 116 116 1/4

Target output:
BookMakerId=1, BookMakerName, BetId=1, BetName, OddsValue, BetId=2, BetName, OddsValue, BetId=3, BetName, OddsValue
BookMakerId=2, BookMakerName, BetId=1, BetName, OddsValue, BetId=2, BetName, OddsValue, BetId=3, BetName, OddsValue
BookMakerId=3, BookMakerName, BetId=1, BetName, OddsValue, BetId=2, BetName, OddsValue, BetId=3, BetName, OddsValue
BookMakerId=4, BookMakerName, BetId=1, BetName, OddsValue, BetId=2, BetName, OddsValue, BetId=3, BetName, OddsValue
BookMakerId=5, BookMakerName, BetId=1, BetName, OddsValue, BetId=2, BetName, OddsValue, BetId=3, BetName, OddsValue
BookMakerId=6, BookMakerName, BetId=1, BetName, OddsValue, BetId=2, BetName, OddsValue, BetId=3, BetName, OddsValue

If the number of BetId changes, the columns (a set of BetId, BetName, OddsValue) will be adjusted.

Sort by OddsValue for 3 Bet of 3 bookmakers:
BetId=1, BetName, OddsValue (Highest value put in 1st row)
BetId=2, BetName, OddsValue (Highest value put in 2nd row)
BetId=3, BetName, OddsValue (Highest value put in 3rd row)

How is the SQL?
Reply With Quote
Reply

Tags
fraction

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On