473,609 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL DISTINCT COUNT

for some reason I can't seem to figure this out.

Situation: I'm using vb.net to create a query that will populate a
dataset with zipcode and count that have unique first 3 digits. I want
to create an audit that shows the client that he has so many reocords
in a 3 digit zip.

sampe data
name | zip
john 32118
joe 32114
mike 32112
tom 41111
tim 41121
table needed
3digitzip | count
321 3
411 2
I've tried a few things but I'm just running in circles and losing what
logic I though I had.

my query somewhat looks like this but i have tried a few other querys
that did not work.

QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(left(zip, 3) as
QUANTITY"

The afformentioned query does not give me the totals I need.

I've tried something like:
QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(distinct
left(zip,3) as QUANTITY"

on the above querry I would get an error in visual studio "missing
opererator" error

Sep 23 '06 #1
5 8129
Is the database you're using support temporary tables? If so you could
try "two-stepping" it, by populating a temp table with the left 3
digits of the zip codes, and them doing a count query on the temp
table. By the way, if what I said doesn't work, you may try posting in
a dedicated SQL group for help with your query.

Thanks,

Seth Rowe

JimmyKoolPantz wrote:
for some reason I can't seem to figure this out.

Situation: I'm using vb.net to create a query that will populate a
dataset with zipcode and count that have unique first 3 digits. I want
to create an audit that shows the client that he has so many reocords
in a 3 digit zip.

sampe data
name | zip
john 32118
joe 32114
mike 32112
tom 41111
tim 41121
table needed
3digitzip | count
321 3
411 2
I've tried a few things but I'm just running in circles and losing what
logic I though I had.

my query somewhat looks like this but i have tried a few other querys
that did not work.

QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(left(zip, 3) as
QUANTITY"

The afformentioned query does not give me the totals I need.

I've tried something like:
QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(distinct
left(zip,3) as QUANTITY"

on the above querry I would get an error in visual studio "missing
opererator" error
Sep 23 '06 #2
Im running the query against dbf file.

rowe_newsgroups wrote:
Is the database you're using support temporary tables? If so you could
try "two-stepping" it, by populating a temp table with the left 3
digits of the zip codes, and them doing a count query on the temp
table. By the way, if what I said doesn't work, you may try posting in
a dedicated SQL group for help with your query.

Thanks,

Seth Rowe

JimmyKoolPantz wrote:
for some reason I can't seem to figure this out.

Situation: I'm using vb.net to create a query that will populate a
dataset with zipcode and count that have unique first 3 digits. I want
to create an audit that shows the client that he has so many reocords
in a 3 digit zip.

sampe data
name | zip
john 32118
joe 32114
mike 32112
tom 41111
tim 41121
table needed
3digitzip | count
321 3
411 2
I've tried a few things but I'm just running in circles and losing what
logic I though I had.

my query somewhat looks like this but i have tried a few other querys
that did not work.

QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(left(zip, 3) as
QUANTITY"

The afformentioned query does not give me the totals I need.

I've tried something like:
QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(distinct
left(zip,3) as QUANTITY"

on the above querry I would get an error in visual studio "missing
opererator" error
Sep 23 '06 #3
Hello JimmyKoolPantz,

Check out the GROUP BY and HAVING clauses.

-Boo
for some reason I can't seem to figure this out.

Situation: I'm using vb.net to create a query that will populate a
dataset with zipcode and count that have unique first 3 digits. I
want to create an audit that shows the client that he has so many
reocords in a 3 digit zip.

sampe data
name | zip
john 32118
joe 32114
mike 32112
tom 41111
tim 41121
table needed
3digitzip | count
321 3
411 2
I've tried a few things but I'm just running in circles and losing
what logic I though I had.

my query somewhat looks like this but i have tried a few other querys
that did not work.

QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(left(zip, 3) as
QUANTITY"

The afformentioned query does not give me the totals I need.

I've tried something like:
QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(distinct
left(zip,3) as QUANTITY"
on the above querry I would get an error in visual studio "missing
opererator" error

Sep 23 '06 #4
JimmyKoolPantz,

In SQL Server you could do something like this:

Select Left(zip,3) as ZIPCODE, Count(left(zip, 3)) as QUANTITY From MyTable
Group By Left(zip,3)

Kerry Moorman
"JimmyKoolPantz " wrote:
for some reason I can't seem to figure this out.

Situation: I'm using vb.net to create a query that will populate a
dataset with zipcode and count that have unique first 3 digits. I want
to create an audit that shows the client that he has so many reocords
in a 3 digit zip.

sampe data
name | zip
john 32118
joe 32114
mike 32112
tom 41111
tim 41121
table needed
3digitzip | count
321 3
411 2
I've tried a few things but I'm just running in circles and losing what
logic I though I had.

my query somewhat looks like this but i have tried a few other querys
that did not work.

QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(left(zip, 3) as
QUANTITY"

The afformentioned query does not give me the totals I need.

I've tried something like:
QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(distinct
left(zip,3) as QUANTITY"

on the above querry I would get an error in visual studio "missing
opererator" error

Sep 23 '06 #5
Kerry Moorman,

Thanks, you are correct. I finally figured it out, however, you
solution was about 4 hours quicker than mine. I think what really hurt
me was I was trying to use the keyword distinct. And then, after
trying, trying, and then crashing I became confused. I read alot of
documentation but never once found something on the internet that was
using left in the group by clause.

Thanks again.
Kerry Moorman wrote:
JimmyKoolPantz,

In SQL Server you could do something like this:

Select Left(zip,3) as ZIPCODE, Count(left(zip, 3)) as QUANTITY From MyTable
Group By Left(zip,3)

Kerry Moorman
"JimmyKoolPantz " wrote:
for some reason I can't seem to figure this out.

Situation: I'm using vb.net to create a query that will populate a
dataset with zipcode and count that have unique first 3 digits. I want
to create an audit that shows the client that he has so many reocords
in a 3 digit zip.

sampe data
name | zip
john 32118
joe 32114
mike 32112
tom 41111
tim 41121
table needed
3digitzip | count
321 3
411 2
I've tried a few things but I'm just running in circles and losing what
logic I though I had.

my query somewhat looks like this but i have tried a few other querys
that did not work.

QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(left(zip, 3) as
QUANTITY"

The afformentioned query does not give me the totals I need.

I've tried something like:
QY = "select Distinct(Left(z ip,3) as ZIPCODE, count(distinct
left(zip,3) as QUANTITY"

on the above querry I would get an error in visual studio "missing
opererator" error
Sep 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
51352
by: Dean | last post by:
I want to build query to return how many rows are in this query: select distinct c1, c2 from t1 But SQL won't accept this syntax: select count (distinct c1, c2) from t1 Does someone know how to count multiple distinct columns? Thanks.
2
10527
by: Anne Heddal | last post by:
In the first line I'm trying to count the the unqiue values of the ID column, but I'm getting syntax error, any idea how to format the distinct count? SELECT Count(test.ID) AS IDCOUNT FROM (select distinct test.ID FROM test), Sum(test.balance) AS BAL, test.statement, billing.YYMM FROM billing INNER JOIN test ON billing.ID = test.ID WHERE (((test.invoice) Like "X*") AND ((test.due)=0) AND ((test.collections)=0)) GROUP BY test.statement,...
17
16368
by: keith | last post by:
I am trying to get a exact count of different distinct entries in an Access column. At first, I was trying to work with three columns, but I've narrowed it down to one to simplify it. I've searched Google Groups for Distinct Count and Count, the Microsoft Help file (which apparently has bad links in Office 2003), and looked at other files, but I can't find the answer. The closest I've been able to get is to create a query to find the...
1
14477
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT aggregate function, but there is no reference, at least that I can find anywhere, of how to do this. I have multiple lines fields for which I would like to do a "count distinct", but for simplicity, I am showing an example of only one field. Here is...
7
4084
by: Johnathan Doe | last post by:
I can google search to find the range of values that can be represented in a float by reading up on the IEEE std, but is that the same as how many distinct values that can go in a float type? For instance, floats can distinguish 0.000001 and 0.000002. If I started with 0.000001 and kept adding 0.000001 until I hit some maximum value (FLT_MAX?) and kept a counter of how many times I added 0.000001, would I have a count of how many...
2
55910
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT? These two attempts failed DataRow dr = ds.Tables.Select( "COUNT(DISTINCT(site_name))" ); object x = ds.Tables.Compute( "COUNT(DISTINCT(site_name))", "ProductionCount > 0" );
1
4077
by: Patrick.O.Ige | last post by:
I have a xml file and i want to format it using XSL My XSL file and XML below I needed to do a distinct which is ok on the first node "Code" For the "programDescription" i did below which gets the Count of the nodes and i get the programDescription node but it duplicates for the selected "Code" Node. So if the Count is 3 its shows values "Crazy Training 2" 3 times for Code "PRG004" Any help?
1
2594
by: Bill | last post by:
I'm trying to write a query that will select a distinct count of more than one field. I have records that display user productivity. Each of the records have a time associated with it and I want to be able to tell the distinct count of the products numbers and of the pallets ID that they worked with. Do need to work out some sort of sub-query to do this?
4
4834
by: tom booster | last post by:
Hi All, I'm trying to convert a T-SQl query to DB2. I have two tables policy and policyHolder. I would like a count of the amount of distinct poicyHolders per policy, for a particular set of new policies. select P.policyID, (select count(PH.PolicyHolderId) from PolicyHolder PH where PH.policyID=P.policyID) CountPolicyHolders from Policy P
0
8145
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
8095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8556
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
8236
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
7030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6068
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
4037
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...
0
4103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.