473,803 Members | 3,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help with query

15 New Member
I have a fantasy football league that I am keeping stats for in an Access Database. I need help coming up with a way to calclulate the winning % for each team for their entire career. What I have is a table with the following fields:
Fantasy Team
Season
Week
W/L
Own Score
Vs
Opponent
Opponent Score
Game type

The W/L field will either have a W or a L depending if they won or loss, the Vs field will either have a vs or a @ depending if its a home or away game, and the Game Type field tells if it was a regular season game, playoff game, Super bowl game, or Toilet bowl game.

What I have done so far is I created a query on the above table to sort out just the winners and this new table is called Winners. I then created a crosstab query called Winners_Crossta b that counts the number of Wins each team has had for each season. So now I have totals wins. I then did the same thing for losses to end up with a query called Loosers_Crossta b. The last thing I did was to create another query called WinPercentage and added the Winners_Crossta b and Loosers_Crossta b and linked the two tables by Fantasy team. The fields include:
Fantasy Team
Count of Wins
Count of Losses
Win%
The win% field is one I added manually and is a calculation of
wins/(wins+losses)*1 00

This works fine except for when a team has no wins or no losses. If a team went 14-0 then the team doesn't show up in the WinPercentage query. I understand why it doesn't but I don't know how to get around this. I hope I made this clear enough for you to give me some quidance. I am new to databases and just started learning Access about 4 months ago.

Thanks for your help,

Scott
Oct 10 '07
28 1807
G8tors
15 New Member
Shoot, that didn't work either. Still getting overflow error.

I definetly owe you a few beers after this is all done.
Oct 11 '07 #11
MMcCarthy
14,534 Recognized Expert Moderator MVP
Shoot, that didn't work either. Still getting overflow error.

I definetly owe you a few beers after this is all done.
Leave the OrderBy off for the moment and see if there is still an error.
Oct 11 '07 #12
G8tors
15 New Member
OK the query runs now but math isn't right and some win% fields say #Error

Total Of W Total Of L Fantasy Team win%
1 1 Annihilators 9.0909090909090 9
0 0 Ballbusters #Error
0 0 Bean Counters #Error
0 0 Big Johnson #Error
0 0 DandBChampions #Error
0 0 Dirt Farmers #Error
2 1 Drunken Sailors 9.5238095238095 2
0 1 Ever Spewing Vomit Dogs 0
2 0 Fangs 10
0 0 Fighting Amish #Error
.....
Oct 12 '07 #13
MMcCarthy
14,534 Recognized Expert Moderator MVP
OK lets go back to the beginning. I don't think you need the crosstab queries as the base for this query. Try running this query instead.

Expand|Select|Wrap|Line Numbers
  1. SELECT [SB Games].[Fantasy Team], Count([SB Games].[W/L]="W") AS [Total Of W], Count([SB Games].[W/L]="L") AS [Total Of L], [Total Of W] / NZ([Total Of W]+[Total Of L],1)*100 As [win%]
  2. FROM [SB Games]
  3. GROUP BY [SB Games].[Fantasy Team]
  4. ORDER BY [Total Of W] / NZ([Total Of W]+[Total Of L],1)*100 DESC;
  5.  
Oct 12 '07 #14
G8tors
15 New Member
I made the changes you suggested and when I run the query, a "Enter Parameter Value" window pops up and asks me for Total of W and once I enter a number and hit ok another "Enter Paramater Value" window asks me for Total of L.

The result, no matter what numbers I enter, is:

Fantasy Team Total Of W Total Of L win%
Madcaps 2 2 50
Jawjackers 1 1 50
I M Toast 1 1 50
Flying Monkeys 2 2 50
Fangs 2 2 50
Ever Spewing Vomit Dogs 1 1 50
Drunken Sailors 3 3 50
Annihilators 2 2 50

Can you use IF ELSE statements is SQL? For example, in the above code where we were getting the overflow error, if wins + losses = 0 then win % = 0 else win% = wins/(wins+losses)*1 00.
Oct 12 '07 #15
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this...

Expand|Select|Wrap|Line Numbers
  1. SELECT [SB Games].[Fantasy Team], 
  2. NZ(Count([SB Games].[W/L]="W"),0) AS [Total Of W],
  3. NZ(Count([SB Games].[W/L]="L"),0) AS [Total Of L], 
  4. [Total Of W] / NZ([Total Of W]+[Total Of L],1)*100 As [win%]
  5. FROM [SB Games]
  6. GROUP BY [SB Games].[Fantasy Team]
  7. ORDER BY [Total Of W] / NZ([Total Of W]+[Total Of L],1)*100 DESC;
  8.  
If that doesn't work remove the orderby line as that is probably the problem. If that solves it we will explore some options for the orderby line.
Oct 12 '07 #16
G8tors
15 New Member
the parameter window still comes up for both wins and losses and numbers don't look right.

When I removed the Oder By line it runs without the parameter window opening up but the numbers are still not right.

Fantasy Team Total Of W Total Of L win%
Annihilators 2 2 9.0909090909090 9
Drunken Sailors 3 3 9.0909090909090 9
Ever Spewing Vomit Dogs 1 1 9.0909090909090 9
Fangs 2 2 9.0909090909090 9
Flying Monkeys 2 2 9.0909090909090 9
I M Toast 1 1 9.0909090909090 9
Jawjackers 1 1 9.0909090909090 9
Madcaps 2 2 9.0909090909090 9

Results should be:
Annihilators 1-1
Drunken Sailors 2-1
ESVD 0-1
Fangs 2-0
Flying Monkeys 2-0
I M Toast 0-1
Jawjackers 0-1
Madcaps 0-2

It looks like it is adding the two numbers and then using that number for both wins and losses.
Oct 12 '07 #17
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this...

Expand|Select|Wrap|Line Numbers
  1. SELECT [SB Games].[Fantasy Team], 
  2. Sum(IIf([SB Games].[W/L]="W",1,0)) AS [Total Of W],
  3. Sum(IIf([SB Games].[W/L]="L",1,0)) AS [Total Of L],
  4. [Total Of W] / NZ([Total Of W]+[Total Of L],1)*100 As [win%]
  5. FROM [SB Games]
  6. GROUP BY [SB Games].[Fantasy Team]
  7.  
Oct 12 '07 #18
G8tors
15 New Member
Thats almost working, but I can't sort the Win% field.

When I try it with desceding Win% the parameter window pops up again.

Do you know of any links that talk about the sum iif statement and nz so I can learn more about that? I'm going to look in the articles section again.
Oct 12 '07 #19
MMcCarthy
14,534 Recognized Expert Moderator MVP
OK put the code in the query without the Order by. Switch to Access Design view and set win% to descending.

Expand|Select|Wrap|Line Numbers
  1. SELECT [SB Games].[Fantasy Team], 
  2. Sum(IIf([SB Games].[W/L]="W",1,0)) AS [Total Of W],
  3. Sum(IIf([SB Games].[W/L]="L",1,0)) AS [Total Of L],
  4. [Total Of W] / NZ([Total Of W]+[Total Of L],1)*100 As [win%]
  5. FROM [SB Games]
  6. GROUP BY [SB Games].[Fantasy Team]
  7.  
As for the functions used

I used sum with an IIf statement returning either 1 or 0 as it seems to give a better result.

NZ(condition, value) simply evaluates a condition and if null or 0 it will return whatever is in as value otherwise it returns the result.

Mary
Oct 13 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3058
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought I'd ask other programmers what information they find useful. Below is a typical class I've...
9
3140
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
6
2430
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs. the table structure is the following Job TypeID
3
1867
by: pw | last post by:
Hi, I am having a mental block trying to figure out how to code this. Two tables: "tblQuestions" (fields = quesnum, questype, question) "tblAnswers" (fields = clientnum, quesnum, questype, answer) They are related by quesnum and questype. There are records in
7
2373
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of which a part may be composed. I have a table of parts and their subparts. The problem is that each of those subparts may be composed of smaller component parts. The subpart would then be listed in the Part field linked to each of its subparts in...
3
10673
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
0
2263
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script in hopes on not having to trouble others on those. But here it goes...
10
2596
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only tool you know how to use is a hammer, every problem tends to look like a nail. That said, I could solve my problem in C, but it's not the right tool. I need to come into the Windows world, and I need to get this done in Access or something...
7
2038
by: Rnykster | last post by:
I know a little about Access and have made several single table databases. Been struggling for about a month to do a multiple table database with no success. Help! There are two tables. First has about 30 fields. Every entry in this table will be unique. Second table has about 7 fields and is for reference - strictly a look up type table. I want to use one field, say FAMILY in the first table to look up any one of the 400 items in the...
3
2563
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks like the following: <a href="?searchtype=2">Community</a>
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.