473,672 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count() Function Help

Ok ... so I'm looking at a query where im trying to show a bunch of
columns counted up based on criteria ...

So far i've been able to count all the rows up and show them ... and
also count up one column based on the criteria (value = yes) ... but
not both at the same time ...

When i try it with all of them, all of them are either the same number
or no numbers at all ...
So to get all the rows i just do

SELECT count(col1), count(col2), count(col3) from table;

And that give me ALL the row count ...

So to get a single column with the correct criteria i do:

SELECT count(col1) from table where col1='yes';

And this gives me the correct number im looking for, but for only 1 row
I've tried this with both AND and OR's:

SELECT count(col1), count(col2), count(col3) from table where col1=yes
AND/OR col2 = yes AND/OR etc ...

AND gives me '0' and OR gives me '12' and the cols should be 3,2,2
respectively. I understand the logic behind these wrong numbers, i
just dont know the logic to get the correct numbers ...

.... any ideas?!

Aug 31 '06 #1
2 2593
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If the columns are truly Yes/No columns, their values should always be
zero or negative one (0 | -1). To count all the True (-1) columns use
the SUM() function like this:

SELECT ABS(SUM(col1)) AS col1_trues, ABS(SUM(col2)) As col2_trues, ...

To count all the False (0) columns use the SUM() function like this:

SELECT ABS(SUM(NOT col1)) AS col1_falses, ...

The expression (NOT col1) will evaluate to true (-1) if the column value
is False; it will evaluate to false (0) if the column value is True.
--
MGFoster:::mgf0 0 <atearthlink <decimal-pointnet
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRPeNOoechKq OuFEgEQJq2QCeN1 5yjS4Ti48k3GuSQ 1cY81+RBpsAoMwA
91mUHgwATjXY6TN EbihETX7R
=jtcL
-----END PGP SIGNATURE-----
Dr******@gmail. com wrote:
Ok ... so I'm looking at a query where im trying to show a bunch of
columns counted up based on criteria ...

So far i've been able to count all the rows up and show them ... and
also count up one column based on the criteria (value = yes) ... but
not both at the same time ...

When i try it with all of them, all of them are either the same number
or no numbers at all ...
So to get all the rows i just do

SELECT count(col1), count(col2), count(col3) from table;

And that give me ALL the row count ...

So to get a single column with the correct criteria i do:

SELECT count(col1) from table where col1='yes';

And this gives me the correct number im looking for, but for only 1 row
I've tried this with both AND and OR's:

SELECT count(col1), count(col2), count(col3) from table where col1=yes
AND/OR col2 = yes AND/OR etc ...

AND gives me '0' and OR gives me '12' and the cols should be 3,2,2
respectively. I understand the logic behind these wrong numbers, i
just dont know the logic to get the correct numbers ...

.... any ideas?!
Sep 1 '06 #2
Damn dude ... life saver!!!
Totally forgot -1 and 0 would be recorgnized as yes or no!

Sep 1 '06 #3

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

Similar topics

1
6467
by: Irfan | last post by:
Hello, I am having some problem with count function. I have a report in which has grouping by a person wise and sub grouping in invoied status e.g.. the output will be Irfan Records (First Grouping by Person Wise) Total Number of Records = 30 (I am using count("*") funtion to get this and
9
10838
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 exceeded....
3
4581
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly appreciated. I've compiled the following VB.NET into a DLL: Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Collections
8
4274
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this...
3
26223
by: Kuups | last post by:
Hi! I have a question regarding the count if character within a string like for example I have a string of e.g. 123#123# I would like to determine what is the code? of getting the # sign
3
13953
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: The problem here is PHP not MySQL, in MySQL everything works just fine. Here is the query that I wrote for getting the number of how much
22
12467
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 moConn.Mode = adModeReadWrite' or using default...same result
3
2706
by: waynejr25 | last post by:
can anyone help me add a function that will count the occurance of each word in an input file. here's the code i have so far it counts the number of characters, words, and lines but i need the occurance of each word. #include <fstream> #include <iostream> #include <string> #include <cstdlib> using namespace std;
1
3605
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. <? //////////////////////////////////////////////////////////// //
0
8502
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8418
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
8844
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...
0
7466
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
6254
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
5720
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4239
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1834
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.