473,801 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with simple querry please!

OK, I'm having a brain freeze.

I have a table like this:

Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
PO Stimpy 555-8888

and I want to a querry that produces this:

Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 3
SG Moe 553-4444 3
SG Curly 666-8888 3
PO Ren 222-9999 2
PO Stimpy 555-8888 2
I try this:

SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name, Phone

and I get
Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 1
SG Moe 553-4444 1
SG Curly 666-8888 1
PO Ren 222-9999 1
PO Stimpy 555-8888 1
What am I missing or doing wrong?

Thanks!

Pete

Aug 8 '06 #1
5 1850
Hi,
SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name, Phone
I guess you should't be grouping by "Phone", since that makes all
records unique again. Try:

SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name

I do hope this helps...

Regards,

Onno

Aug 8 '06 #2
Won't work. I get an error when the Group BY line does not match the
Select By line.
Both have to have the same fields.

Pete

on****@gmail.co m wrote:
Hi,
SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name, Phone

I guess you should't be grouping by "Phone", since that makes all
records unique again. Try:

SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name

I do hope this helps...

Regards,

Onno
Aug 8 '06 #3
On 8 Aug 2006 02:26:11 -0700, "Clownfish" <cl*********@ya hoo.com>
wrote:

Name is a reserved word. Don't use it for field names. Change it to
CustomerName, EmployeeName or whatever, and try again. Your SQL is
fine.

-Tom.
>OK, I'm having a brain freeze.

I have a table like this:

Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
PO Stimpy 555-8888

and I want to a querry that produces this:

Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 3
SG Moe 553-4444 3
SG Curly 666-8888 3
PO Ren 222-9999 2
PO Stimpy 555-8888 2
I try this:

SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name, Phone

and I get
Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 1
SG Moe 553-4444 1
SG Curly 666-8888 1
PO Ren 222-9999 1
PO Stimpy 555-8888 1
What am I missing or doing wrong?

Thanks!

Pete
Aug 8 '06 #4
Nope.. still no go.

I tried this TABLE1

Office StaffName Arrive
------------------------------------------------------
CO N/A 8/7/2006
PO Hamster 8/20/2006
PO Monkey 8/20/2006
SG Trout 7/20/2006
SG Bass 8/20/2006
SG N/A 8/20/2006
SG Bass 8/7/2006

SELECT Table1.Office, Table1.StaffNam e, Table1.Arrive,
Count(Table1.Of fice) AS CountOfOffice
FROM Table1
GROUP BY Table1.Office, Table1.StaffNam e, Table1.Arrive;

And I still get all ones in the counted field.

Office StaffName Arrive
CountOfOffice
----------------------------------------------------------------------------------------------
CO N/A 8/7/2006
1
PO Hamster 8/20/2006
1
PO Monkey 8/20/2006
1
SG Trout 7/20/2006
1
SG Bass 8/20/2006
1
SG N/A 8/20/2006
1
SG Bass 8/7/2006
1

I am probably doing this all wrong. Let me describe what I really need
and then perhaps someone can show me how dumb I have been.

My GOAL is to create a report that would print the following:
Office StaffName Arrive
------------------------------------------------------
CO NO CHANGES 8/7/2006
PO Hamster 8/20/2006
PO Monkey 8/20/2006
SG Trout 7/20/2006
SG Bass 8/20/2006
SG Bass 8/20/2006

The querry would print all records EXCEPT the 6th one, because the 6th
record has the text "N/A" in [StaffName] AND there are more than 1
record in it's "SG" group [Office]

I would like a statement that works like this:

Select all records EXCEPT those with ( "N/A" in [StaffName] AND
Count(Office) >1 )

Any ideas?

Thanks guys! (and gals!)

Peter

Tom van Stiphout wrote:
On 8 Aug 2006 02:26:11 -0700, "Clownfish" <cl*********@ya hoo.com>
wrote:

Name is a reserved word. Don't use it for field names. Change it to
CustomerName, EmployeeName or whatever, and try again. Your SQL is
fine.

-Tom.
OK, I'm having a brain freeze.

I have a table like this:

Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
PO Stimpy 555-8888

and I want to a querry that produces this:

Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 3
SG Moe 553-4444 3
SG Curly 666-8888 3
PO Ren 222-9999 2
PO Stimpy 555-8888 2
I try this:

SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name, Phone

and I get
Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 1
SG Moe 553-4444 1
SG Curly 666-8888 1
PO Ren 222-9999 1
PO Stimpy 555-8888 1
What am I missing or doing wrong?

Thanks!

Pete
Aug 8 '06 #5
"Clownfish" <cl*********@ya hoo.comwrote in
news:11******** **************@ b28g2000cwb.goo glegroups.com:
OK, I'm having a brain freeze.

I have a table like this:

Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
PO Stimpy 555-8888

and I want to a querry that produces this:

Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 3
SG Moe 553-4444 3
SG Curly 666-8888 3
PO Ren 222-9999 2
PO Stimpy 555-8888 2
I try this:

SELECT Office, Name, Phone, Count(Office) AS OfficeCount
FROM Table
GROUP BY Office, Name, Phone

and I get
Office Name Phone OfficeCount
----------------------------------------------------------
SG Larry 555-1212 1
SG Moe 553-4444 1
SG Curly 666-8888 1
PO Ren 222-9999 1
PO Stimpy 555-8888 1
What am I missing or doing wrong?

Thanks!

Pete

What you want is incorrect.... 3 relates only to Office SG, not
to office and name and phone.2 relates to office PO not to
office + name + phone.

But, you can do it with 2 queries. And if you are ambitious,
you can merge the two queries into one querydef.

Query1
Select Office, count("*") as OfficeCount from table Group By
Office;

Query2
Select table.office,ta ble.name,table. phone,Query1.Of ficeCount
from table inner join query1 on table.office = query1.office;

The whole works in 1 query:
Select table.office,ta ble.name,table. phone,(SELECT count("*") as
X from table alias Y where Y.office = Z.office) as OfficeCount
from table alias Z;

It's a pain to write and debug a query in a query, so stick with
the two query system for a few years.

Not that if you try to run any of these queries, Access will
complain about using reserved words (table, name)

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 8 '06 #6

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

Similar topics

2
3195
by: Eric Kincl | last post by:
Hello, I have an array of data in PHP. I would like to insert each member of the array into it's own row in SQL. The array is of variable length, so it would have to be dynamic code. How would I go about this? Would I stick the SQL querry generation and actual querry into a while loop? This would generate a lot of traffic between the SQL server and the PHP script. The arrays are each over 1000 members long, however, this is an rare...
17
2650
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in directly. so I need a way doing this. so I check to see if the ifp value is null and if so then assign it a value. is this correct?
25
11111
by: Andreas Fromm | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Im building an user database with many tables keeping the data for the Address, Phone numbers, etc which are referenced by a table where I keep the single users. My question is, how do I get the "Id"-value of a newly inserted address to store it in the referencing user table:
0
964
by: serge calderara | last post by:
Dear all, I need to develop an analysis tool which collects data from an SQL server database. I plan to build it as a web application because more that one user might access those data. The problem I get is that the application should handle the fact that my final user do not know anything about SQL language so the interface should be simple for use. The point I have completly blind is the fact that I do not know in advance
10
1681
by: Maulik Thaker | last post by:
Hi ppl, I have a querry based on ID. Suppose if i have got two primary keys (ID) and one foreign key (IDREF) in the same attribute, is there a way to use them. For example :
2
1117
by: serge calderara | last post by:
Dear all, I have a web application build with ASP 1.1 which has a querry form based on fields where users need to enter a date/time value for data collection. On my Web server the date time foprmat is set with US (english). The final querry will be something like : " select * from Table 1 where DATE_TIME > @DateTimeParam"
3
2906
by: samearle | last post by:
Help me write this for MS access, I'm used to Oracle - SELECT Users.*, group_1, group_2, group_3 from (select UserInGroup.UserID, max(decode(GroupID, 1, GroupID, null)) as group_1,
0
1284
by: getmeidea | last post by:
I have the following tables, 1> employee_master(emp_id int primary key, emp_name varchar(100)); 2> employee_salary_payment(salary_rid int primary key, emp_id int, sal_date date, paid_amt int); The tables, employee_master and employee_salary_payment have one to many relation. I need to list the salary payment done for the employee having id = 10. Here I use two different querry to work. Querry 1: Select em.emp_id, em.emp_name,...
2
1468
by: dipalichavan82 | last post by:
i came across a article, where it was mentioned if we want a dynamic querry to fire then use parameterized querry e.g. string inputcity=textbox.text; SqlCommand cmd = new SqlCommand("select * from Customers where city= '" + inputCity + " ' "; Don't ever build a query this way! as this leads to hacking. instaed do it like this:
0
9556
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
10516
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
10292
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
10262
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
10052
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...
0
9101
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
7589
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
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2959
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.