473,569 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

count feature (group by)

If you have a select with 2 attributes where you group by one attribute
and do a count() for the second attribute, if the count() is 0 then
that row is never displayed. How would you instead see a line item
where you list the attribute with 0 as the count.

Aug 16 '06 #1
1 1835

"sammy" <va******@cs.st anford.eduskrev i en meddelelse
news:11******** *************@7 5g2000cwc.googl egroups.com...
If you have a select with 2 attributes where you group by one attribute
and do a count() for the second attribute, if the count() is 0 then
that row is never displayed. How would you instead see a line item
where you list the attribute with 0 as the count.
I'm not sure I understand what you're asking. So this is based on some
assumptions about the nature of your problem:

If you have a table with two columns, ColA and ColB, with these data:

1, 4
2, 5
3, 1
1, 8
5, 1

and you have a query like this:

SELECT ColA, COUNT(ColB)
GROUP BY ColA

the result would be

1, 2
2, 1
3, 1
5, 1

It's my understanding (wich may be wrong) that
(if the possible values of ColA is 1-5)
you would have liked the result to be

1, 2
2, 1
3, 1
4, 0
5, 1

However, this is based on the knowledge of the possible values of ColA. SQL
has no way of knowing about these values if they are not present in the
table, hence the query will count only the rows whose group values are
present in ColA of the table.

If you really want to return a count for each possible value, regardless if
they are present in the table, you need to create a table with the possible
values (one column only):

Then you could modify your query a little:

SELECT Allval.ColA, COUNT(ColB)
FROM Allval
LEFT JOIN Table ON Allval.ColA = Table.ColA
GROUP BY Allval.ColA

Aug 16 '06 #2

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

Similar topics

9
10819
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 LDIFDE as a comparison I get the same results. No members means just that, an empty group. Zero means that the DirectorySearcher.SizeLimit has been...
30
3284
by: Raymond Hettinger | last post by:
Proposal -------- I am gathering data to evaluate a request for an alternate version of itertools.izip() with a None fill-in feature like that for the built-in map() function: >>> map(None, 'abc', '12345') # demonstrate map's None fill-in feature The motivation is to provide a means for looping over all data elements
1
4512
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 have created an access query to track the number of training hours for a training group. The query is working except for one piece of data and I hoping...
22
12437
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=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient...
3
3100
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php, I use: $query2 = "SELECT id, order_no, price, count(item_no) as count from production where item_no = '27714";
2
2102
by: AtCor | last post by:
SELECT Sheet1$. AS , CASE Sheet1$. WHEN 'CSPP100A2344' THEN '0' END AS Extension, SUBSTRING(Sheet1$., 1, 4) AS , SUBSTRING(Sheet1$., 5, 8) AS , SUBSTRING(Sheet1$., 1, 4) + '_' + SUBSTRING(Sheet1$., 5, 8) AS , Sheet1$. + '_' + SUBSTRING(Sheet1$., 1, 4) + '_' +...
3
10006
by: cmartin1986 | last post by:
I have written a sql query and I need it to return 0 when it doesn't find any matches to my criteria. I have tried adding iif statements, tried sum, and just Count, all of these methods work fine to return the values when it finds matches, but i need it also to return a 0 when there are no matches. Here is what I got. SELECT "CAL Recieved"...
1
3601
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent via an email function. But just can't figure it out. <? //////////////////////////////////////////////////////////// //
4
1611
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 Balance. What I want to do is run the query to count the number of Companies within a country. As there are thousands of records one company may be in the...
0
7619
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...
0
8138
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...
0
6290
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...
1
5514
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...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
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...

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.