473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

My query is not giving me the right count with try to total columns

I am trying to run two queries. One query is doing a count to figure out how many total sales there were each year based on the assessor. That query is working fine. On the other query, I'm trying to get a count of the property type grouped together by year and assessor. The problem with this query is that somtimes the property type is blank and that's okay, but the count is not counting the blanks, so my numbers aren't matching up in the two queries. For instance, say I've got 5 sales in 2005 that do not have a property type listed. The query will pick up that there is a blank property type, but in the count column, it has zero instead of 5. This is really hard to explain without showing, so let me know if you need me to explain further. I'm at a loss on how to get my numbers to match up.
Oct 30 '09 #1
5 1700
ajalwaysus
266 Expert 100+
@stateemk
Could you please post the code in your query so we can actually see what you are doing?

-AJ
Oct 30 '09 #2
Here's the query that is not giving me the right count. When the "Property Type" is null, it will show zero in the Count column.

Expand|Select|Wrap|Line Numbers
  1. SELECT [Residential Sale].[County Link], [Residential Sale].[Sale Year], [Residential Sale].[Property Type], [Residential Sale].[Source Assessor], Count([Residential Sale].[Property Type]) AS [CountOfProperty Type]
  2. FROM [Residential Sale]
  3. GROUP BY [Residential Sale].[County Link], [Residential Sale].[Sale Year], [Residential Sale].[Property Type], [Residential Sale].[Source Assessor]
  4. HAVING ((([Residential Sale].[County Link]) Is Not Null) AND (([Residential Sale].[Property Type])="ml" Or ([Residential Sale].[Property Type])="ms" Or ([Residential Sale].[Property Type])="sf" Or ([Residential Sale].[Property Type])="va" Or ([Residential Sale].[Property Type])="vl" Or ([Residential Sale].[Property Type]) Is Null) AND (([Residential Sale].[Source Assessor])="assessor" Or ([Residential Sale].[Source Assessor])="appraiser" Or ([Residential Sale].[Source Assessor])="mls" Or ([Residential Sale].[Source Assessor])="buyer" Or ([Residential Sale].[Source Assessor])="seller" Or ([Residential Sale].[Source Assessor]) Is Null))
  5. ORDER BY [Residential Sale].[County Link], [Residential Sale].[Sale Year] DESC , [Residential Sale].[Property Type], [Residential Sale].[Source Assessor];
Oct 30 '09 #3
Sorry, I meant to include this in my previous post. When the "Property Type" is null, it will show zero in the CountOf Property Type column even though there are one or more records with a null property type.
Oct 30 '09 #4
ajalwaysus
266 Expert 100+
You don't have to count on the [Property Type] field, if you have an ID field or something like that, that you know will NEVER be null, then your count will be correct. The count function counts the rows regardless on what it is on as long as it's never null.

Let me know if this works,
-AJ
Oct 30 '09 #5
NeoPa
32,556 Expert Mod 16PB
When wishing to count all rows, as opposed to counting the number of occurrences of a particular field across all the rows, you should use the aterisk (*).

Your first line would then be (formatted so that it can be read) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Residential Sale].[County Link],
  2.        [Residential Sale].[Sale Year],
  3.        [Residential Sale].[Property Type],
  4.        [Residential Sale].[Source Assessor],
  5.        Count(*) AS [CountOfProperty Type]
I wouldn't use the name [CountOfProperty Type] either, as that doesn't mean not what you want.
Oct 30 '09 #6

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

Similar topics

2
by: Debbie Davis | last post by:
Hi there, SQL 2000 I have the following query: SELECT sponsor, COUNT(sponsor) * 2 AS total FROM Referrals GROUP BY sponsor Works great, returns the sponsor and the total * 2 of their...
6
by: Pedro Fonseca | last post by:
Greetings! Can someone please help me to crack this problem? I have 4 tables: Subject, Forum, Topic and Post. A Subject groups various Forums, a Forum groups various Topics, and a Topic groups...
2
by: mhodkin | last post by:
I created a query in which I have grouped data by City. I wish to calculate the percent of each value, e.g. City/(Total count of all Cities), in tbe next column of the query. I can't seem to...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
0
by: rdnews | last post by:
Dear group, I got excellent help here a while back in optimizing a slow query, so I thought I'd try again with another one... I have a small table, around 3000 rows with two columns. One is a...
0
by: aaron.reese | last post by:
Hi guys, I'm having some trouble getting a query to return the information I require. Tables: EventMaster holds the venue details Event holds the date of the event and some other irrelevant...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
4
by: odavison | last post by:
I'm currently running a crosstab query that displays the total amounts of Appointments that each Consultant. Currently it is Consultant ID as the Rows, and Appointment Date as the top headings,...
2
by: kveerareddy | last post by:
How can i get the total rows of a table: If i use "select count(*) from <tablename>" it will take lot of time to get the total row count. for example in MSSQL we have "SELECT ROWS FROM...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.