473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sql count query

11 New Member
Hi all

I need help in dis, i m working on a project and here i have to design a query and it has some values(say Student ID) in columns which is repeating. So i want all the columns in output and also the number of times that Student ID is same in every record corrosponding to that student ID.......plz help itz urgent....!!!
Jun 28 '10 #1
6 2622
code green
1,726 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. COUNT(student ID) GROUP BY student ID
Jun 28 '10 #2
Anubhav Mital
11 New Member
hey thanx for reply but that is not enough i want all the other columns in my output too and also this count

eg
student id

A
B
C
A
B
A

then i m expecting output to be

Student id
count
A 3
B 2
C 1
A 3
B 2
A 3
Jun 28 '10 #3
code green
1,726 Recognized Expert Top Contributor
i want all the other columns in my output too
Then put the other columns in.
Do you get the correct result without the GROUP BY?
Jun 28 '10 #4
Anubhav Mital
11 New Member
SELECT customer_name, COUNT(city) as "Distinct Cities"
FROM customers
GROUP BY customer_name;



i tried using this query and it worked but it is giving me the unique values only i.e. it is not repeating them as i want them..... and also in case i SELECT all the other fields it again gives error...

also as u said if i wont use GROUP BY then it will just give me a total number(of STUDENT/CUSTOMER ID) dat is of no use for me
Jun 28 '10 #5
manxman777
6 New Member
@Anubhav Mital
you need a compound query

the easiest is to save your count query (don't use spaces in field names like DistinctCities) as a separate query called CityCount (or similar)

SELECT customer_name, COUNT(city) as "DistinctCities"
FROM customers
GROUP BY customer_name;

then create another query like this

SELECT customers.*, CityCount.DistinctCities from customers INNER JOIN CityCount ON customers.customer_name = CityCount.customer_name;

(not tested; I may have made a typo)

Richard "Manxman" Killey
Jun 28 '10 #6
Anubhav Mital
11 New Member
KK thanx buddy ....i also found the similar solution to it but i hadnt implemented it yet.. i hope it will work thanx for ur help...i case of any queries i will disturb u again..:)
Jun 28 '10 #7

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

Similar topics

6
by: Nicolae Fieraru | last post by:
Hi All, I have a query, Select Count(BoolField) from tblMyTable, Where BoolField = true. If I run the query by itself, it returns the number of true records I want to use the result of that...
1
by: Greg Smith | last post by:
I am trying to write a SQL query that will return a record count to my C# application. I wrote the following query: ALTER PROCEDURE up_justification_duplicate AS SELECT COUNT(*) FROM...
12
by: briansmccabe | last post by:
Does anyone have a good approach to displaying in PHP a simple COUNT query that is performed on a table in a MySQL db? Thanks
6
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...
1
by: John | last post by:
Hi I have a field that can have either A, B or C as its value. I need to write a query that will return the number of A's, B's & C's in the field X for a given criteria and then the total...
1
by: AJ | last post by:
Hi all, I have the following data: AnswerID SubmitID AnswerQuestion OptionSelected 0001 1 1 1 0002 1 1 ...
3
by: Jennifer | last post by:
I have a table that I am trying to do a query on. Table is named GPFCount2. CREATE TABLE ( NULL , NULL , NULL , NULL , NULL ,
1
lwwhite
by: lwwhite | last post by:
When a user clicks OK on form "SelectDefaults," I want to open form "Welcome" if the results of query "qry_todo_overdue" = 0 or form "OverdueToDo" if the results >= 1. First, I assume that I need to...
3
WyvsEyeView
by: WyvsEyeView | last post by:
This seems like it should be so easy to do. I have a table, called tblTopics. Each topic can have one or more instances, contained in a table called tblTopicInst. tblTopics is bound to a form called...
4
by: Sharkiness | last post by:
Hi, I'm new to using queries in Access and am stuck on trying to run a query from a table. I have thousands of records with fields such as customer name, Company Name, Company Country and...
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...
1
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...
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.