473,396 Members | 1,770 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,396 software developers and data experts.

Counting posts in forum

22
Hi Peoples
I have the following query to retrieve data from the db. 2 of the things it has to do is give me the date of the last post and a count of the post records in each of the categories.
The last post date works fine but i cannot get the COUNT(threadID) to return anything but 1 record for each category.
Can someone PLEASE help
query is as follows:
---------------------------
<cfquery name="showcategories" datasource="#dsn#">
SELECT categories.catID, category, description, MAX(postdate) AS lastpost, COUNT(threadID) as postCount
FROM categories, threads
where categories.catID = threads.catID
Group by postDate, categories.catID, category, description
ORDER BY Category ASC, PostDate DESC
</cfquery>

by the way it makes no difference if I add the threadID to the group by line
thanks in advance
Grabit
Mar 10 '07 #1
7 1384
MSeda
159 Expert 100+
I think you need to drop postDate from group by.
Mar 10 '07 #2
grabit
22
I think you need to drop postDate from group by.
i tried that but without it in there i get the following
Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] You tried to execute a query that does not include the specified expression 'PostDate' as part of an aggregate function.
Mar 10 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
i tried that but without it in there i get the following
Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] You tried to execute a query that does not include the specified expression 'PostDate' as part of an aggregate function.
That's because you have it in the ORDER BY. You have also used a full outer join. Try this instead ...

Expand|Select|Wrap|Line Numbers
  1. SELECT categories.catID, category, description, 
  2. MAX(postdate) AS lastpost, COUNT(threadID) as postCount 
  3. FROM categories INNER JOIN threads   
  4. ON categories.catID = threads.catID   
  5. GROUP BY categories.catID, category, description   
  6. ORDER BY Category ASC, lastpost DESC   
  7.  
Mary
Mar 10 '07 #4
grabit
22
That's because you have it in the ORDER BY. You have also used a full outer join. Try this instead ...

Expand|Select|Wrap|Line Numbers
  1. SELECT categories.catID, category, description, 
  2. MAX(postdate) AS lastpost, COUNT(threadID) as postCount 
  3. FROM categories INNER JOIN threads   
  4. ON categories.catID = threads.catID   
  5. GROUP BY categories.catID, category, description   
  6. ORDER BY Category ASC, lastpost DESC   
  7.  
Mary
Hi Mary thanks for the reply
when i use that code i get the following error - can this be fixed and if so how please?

Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

The error occurred in C:\CFusionMX\wwwroot\Forum\mainPage.cfm: line 22

20 : <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
21 :
22 : <cfquery name="showcategories" datasource="#dsn#">
23 : SELECT categories.catID, category, description,
24 : MAX(postdate) AS lastpost, COUNT(threadID) as postCount



--------------------------------------------------------------------------------

SQL SELECT categories.catID, category, description, MAX(postdate) AS lastpost, COUNT(threadID) as postCount FROM categories INNER JOIN threads ON categories.catID = threads.catID GROUP BY categories.catID, category, description ORDER BY Category ASC, lastpost DESC
DATASOURCE forum
VENDORERRORCODE -3010
SQLSTATE 07002

thanks Grabit
Mar 11 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
This is usually caused by a naming problem in one of the fields. Try running the query directly on the database and see what happens. If it still doesn't work check all the field and table names are correct. If there is no problem there then remove the Order By and see if it runs.

Mary
Expand|Select|Wrap|Line Numbers
  1. SELECT categories.catID, category, description, 
  2. MAX(postdate) AS lastpost, COUNT(threadID) as postCount 
  3. FROM categories INNER JOIN threads 
  4. ON categories.catID = threads.catID 
  5. GROUP BY categories.catID, category, description 
  6. ORDER BY Category ASC, lastpost DESC
  7.  
Mar 11 '07 #6
grabit
22
This is usually caused by a naming problem in one of the fields. Try running the query directly on the database and see what happens. If it still doesn't work check all the field and table names are correct. If there is no problem there then remove the Order By and see if it runs.

Mary
Expand|Select|Wrap|Line Numbers
  1. SELECT categories.catID, category, description, 
  2. MAX(postdate) AS lastpost, COUNT(threadID) as postCount 
  3. FROM categories INNER JOIN threads 
  4. ON categories.catID = threads.catID 
  5. GROUP BY categories.catID, category, description 
  6. ORDER BY Category ASC, lastpost DESC
  7.  

Thanks very very very much Mary
took out the order by line and shes away laughing
your a genius. As you will be aware i am a newbie to this sql thing and to find someone who knows what they are doing and are willing to help, is a breath of fresh air on the web today
Again
Thankyou
Grabit
Mar 11 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Thanks very very very much Mary
took out the order by line and shes away laughing
your a genius. As you will be aware i am a newbie to this sql thing and to find someone who knows what they are doing and are willing to help, is a breath of fresh air on the web today
Again
Thankyou
Grabit
You're welcome.

Mary
Mar 11 '07 #8

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

Similar topics

3
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
7
by: Daniel Jahro via DotNetMonster.com | last post by:
Hi! Im trying to pull out the last ten posts in a access dg (*.mdb). Whats the best way to do it? All posts are located in a table named "tblTopic" and the posts automatically get accending...
13
by: rajash | last post by:
Hi I am new to this forum. I have taken a class in C some time ago but now I am reading Kernigan and Richie's book to refresh my knowledge. I think I have forgotten alot and there are no...
17
by: Razii | last post by:
This is specifically regarding U++ which is C++ libraries and IDE (please don't whine whether its on or off topic. Right click on the thread and click on ignore instead of wasting time). This is...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
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,...
0
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...
0
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...

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.