Thanks for all the help so far, my database is starting to come along well now.
I am having trouble with a query at the minute. Basically it goes like this:
I have a main table to my database which holds client info, including city name.
Through a many to many relationship this is conected to a contact table which records contacts with the clients. This table has a field titled outcome in which either 'no reply', 'call later', or returned call' is recorded
What I am trying to do is run a query that will sort and count call types by location (city)
i.e.
[PHP]Count Call type City
3 call later London
6 no reply London
3 call later Birmingham[/PHP]
I hope this reads ok for you, any help is much appreaciated!
14 2385
Hi
Try something like this - Select Count(*), CallType, City From tblClient
-
Group By City, CallType
-
Order By City, CallType
HTH
Steve
Hi
Try something like this - Select Count(*), CallType, City From tblClient
-
Group By City, CallType
-
Order By City, CallType
HTH
Steve
Cheers for that,
I have modified it slighty - SELECT Count(*) AS Expr1, Calls.Subject, tblclient.city
-
FROM contacts INNER JOIN Calls ON tblclient.ContactID = Calls.ContactID
-
GROUP BY Calls.Subject, tblclient.city
-
ORDER BY tblclient.city, Calls.Subject;
Then something strange happens...
I tested it on a 5 record db
thing is it works perfectly for all the records except 2 and 5
for some reason the query returns results like so
Count Subject City
2 no reply london
3 no reply london
etc, as I have said all the other records sort and count perfectly.
the subject field is a text input, I have checked the formatting and it corresponds with that of other records.
The query seems to treat these 2 records as separate counts, anyone got any ideas?
Thanks
NeoPa 32,556
Expert Mod 16PB
Look at the data very carefully.
Are there any extraneous spaces or other white-space chars?
Try this ... - SELECT Count(*) AS Expr1, Calls.Subject, tblclient.city
-
FROM tblclient INNER JOIN Calls ON tblclient.ContactID = Calls.ContactID
-
GROUP BY Calls.Subject, tblclient.city
-
ORDER BY tblclient.city, Calls.Subject;
You never replaced the contacts table name with tblclient
NeoPa 32,556
Expert Mod 16PB
Good spot Mary.
I've added the code tags to the post (#3) so that it's more clearly visible what was used.
Thanks for the help, bit of an oversight there!!
I thought about Neopa's post an decided it would be better to use a dropdown list to select an outcome to avoid the chance of white space errors.
One thing I am trying to sort out is the query display, the dropdown list is as usual supported by an autonumbered table. How do I go about getting the linked text to appear in the query result as opposed to just the autonumber number?
Thanks
NeoPa 32,556
Expert Mod 16PB
Try the Column property of the ComboBox.
Press F1 on the word Column from the VBA window for a fuller explanation of the Column item.
Cheers for that,
I have modified it slighty - SELECT Count(*) AS Expr1, Calls.Subject, tblclient.city
-
FROM tblclient INNER JOIN Calls ON tblclient.ContactID = Calls.ContactID
-
GROUP BY Calls.Subject, tblclient.city
-
ORDER BY tblclient.city, Calls.Subject;
Then something strange happens...
I tested it on a 5 record db
thing is it works perfectly for all the records except 2 and 5
for some reason the query returns results like so
Count Subject City
2 no reply london
3 no reply london
etc, as I have said all the other records sort and count perfectly.
the subject field is a text input, I have checked the formatting and it corresponds with that of other records.
The query seems to treat these 2 records as separate counts, anyone got any ideas?
Thanks
I got the last bit sorted thank you Neopa (again)
I made the corrections that mmccarthy pointed out.
I found out why the counts were running the way I showed, its because of the different call dates, i.e. it counts all the calls from one day and sums them by city and subject. Is there any way to ammend the sql so it sums the totals for the user inputed dates?
Thanks
Stephen
NeoPa 32,556
Expert Mod 16PB
Do you have your latest (as correct as possible) SQL?
Do you have your latest (as correct as possible) SQL?
I'm little further on from my last post - SELECT Count(*) AS Expr1, Calls.Subject, contacts.ContactTypeID, Calls.CallDate
-
FROM contacts INNER JOIN Calls ON contacts.ContactID = Calls.ContactID
-
GROUP BY Calls.Subject, contacts.ContactTypeID, Calls.CallDate
-
HAVING (((Calls.CallDate) Between [Enter Start of Date Range] And [Enter End of Date Range]))
-
ORDER BY contacts.ContactTypeID, Calls.Subject;
It seems when I add the date range option in the above code it changes the type of result
Is this what you're looking for? -
SELECT Count(*) AS Expr1, Calls.Subject, contacts.ContactTypeID
-
FROM contacts INNER JOIN Calls
-
ON contacts.ContactID = Calls.ContactID
-
WHERE [last contact date] Between [Enter Start of Date Range] And [Enter End of Date Range]
-
GROUP BY Calls.Subject, contacts.ContactTypeID
-
ORDER BY contacts.ContactTypeID, Calls.Subject;
-
Mary
NeoPa 32,556
Expert Mod 16PB
I'm little further on from my last post - SELECT Count(*) AS Expr1, Calls.Subject, contacts.ContactTypeID, Calls.CallDate
-
FROM contacts INNER JOIN Calls ON contacts.ContactID = Calls.ContactID
-
GROUP BY Calls.Subject, contacts.ContactTypeID, Calls.CallDate
-
HAVING (((Calls.CallDate) Between [Enter Start of Date Range] And [Enter End of Date Range]))
-
ORDER BY contacts.ContactTypeID, Calls.Subject;
It seems when I add the date range option in the above code it changes the type of result
- SELECT Count(*) AS Expr1, Calls.Subject, contacts.ContactTypeID, Calls.CallDate
-
FROM contacts INNER JOIN Calls ON contacts.ContactID = Calls.ContactID
-
WHERE (Calls.CallDate Between [Enter Start of Date Range] And [Enter End of Date Range])
-
GROUP BY contacts.ContactTypeID, Calls.Subject, Calls.CallDate
-
ORDER BY contacts.ContactTypeID, Calls.Subject;
This is a simple tidy up of your SQL.
Looking at your latest request I'm a little stuck :
You show examples using a field (City) but this isn't in your SQL at all.
Do you want to GROUP BY date alone (have only one result line ever for each date)?
If so, you need to decide what you want to do with the other fields. - ------------Input-------- ----------------Output----------------
-
Date City Value Date (Group) City (?) Value (Sum)
-
1 Jan 2007 London 32
-
1 Jan 2007 Bristol 12
-
1 Jan 2007 London 19 1 Jan 2007 Undefined(?) 63
If they are to be included at all, you need to treat them as some sort of Aggregate. Otherwise you may get extra output lines for each different item found in the field.
In this example I use City but it can be any non-aggregated field in a GROUP BY query.
If the same data had a query with a GROUP BY including the other field (City in this case) you get : - ------------Input-------- ----------------Output----------------
-
Date City Value Date (Group) City (Group) Value (Sum)
-
1 Jan 2007 London 32
-
1 Jan 2007 London 19 1 Jan 2007 London 51
-
1 Jan 2007 Bristol 12 1 Jan 2007 Bristol 12
Just a thank you for all your help, time and patience, my db is now nearly complete.
NeoPa 32,556
Expert Mod 16PB
Good to hear it lostdog. I'm glad to have helped.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthias Haffke |
last post by:
Ok, this is a tricky question for the pro's:
My access sheet:
line, id a, id b, val%
----------------
1, a, ac, 0.04
2, a, ac, 0.28
3, a, ac, 0.015
4, a, ac, 0.205
|
by: Terry E Dow |
last post by:
Howdy,
I am having trouble with the objectCategory=group member.Count attribute.
I get one of three counts, a number between 1-999, no member (does not
contain member property), or 0. Using...
|
by: Hyphessobricon |
last post by:
Hallo,
Indeed, a count of a query with a group by function gives more records than
there are and so for-next structures don't function.
How is this to be mended.
Anyone? Everyone in fact....
|
by: dBNovice |
last post by:
Hey group,
I am trying to do a count of the number of papers in a table. The
table has a PaperID that differentiates each paper , e.g. 004.1. Some
papers are reused. The reused paper is given...
|
by: auron |
last post by:
Hi there,
I have a really stupid and banal problem with showing the results of a
MySQL query in PHP, preciselly with MySQL count() function that gives
to a variable in PHP the result.
NOTE:...
|
by: heckstein |
last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
|
by: MP |
last post by:
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source="...
|
by: Akhenaten |
last post by:
The following snippet (for whatever reason) returns no value for the
count. Suggestions?
$arr = array ("A", "B", "C", "D", "E");
foreach ($arr as $client) {
$count = mysql_query('SELECT...
|
by: petter |
last post by:
Hi!
I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month.
I have an Access database where I want...
|
by: zufie |
last post by:
I have to create a QA report regarding callers calling into a phone
hotline.
The report consists of many checkboxes such as:
Did the IBCCP agency contact you? Yes/NO
How many days passed...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
| |