Clarification needed on the behaviour of count with null values
Hi friends,
I am confused about the result given by the count aggregate function when dealing with null. Please can anybody clarify about that to me. Here is what i tried
CREATE TABLE Demo ( a int);
INSERT INTO Demo VALUES
(1),
(2),
(NULL),
(NULL);
SELECT COUNT(COALESCE(a,0)) FROM Demo WHERE a IS NULL; -- Returns 2
SELECT COUNT(ISNULL(a,0)) FROM Demo WHERE a IS NULL; -- Returns 2
SELECT COUNT(*) FROM Demo WHERE a IS NULL; -- Returns 2
SELECT COUNT(a) FROM Demo WHERE a IS NULL; -- Returns 0
Please can anybody explain me why the result is same for the first three select statements and why not for the last select statement. And what does COUNT(*) actually mean?
With Regards
Abhilash D K
There is a difference to the logic when using a column name versus "*" - which is explained in the documentation (and reading it is the first thing you should do when you do not understand a particularly query/syntax). When you supply a column
(or expression) to the count function, only the non-null values are counted. Isnull and coalesce will obviously replace a NULL values, therefore the result of the expression will be counted.
1 and 2 are effectively the same - you replace a null value in your column with 0 and each query only selects rows with a null column value. The count of non-null values of your expression is therefore 2 - the number of rows in your resultset.
3 is the number of rows in the resultset since you supplied "*" instead of a column. The presence of nulls is irrelevant as documented.
4 is the number of non-null values in the resultset since you DID supply a column. Your resultset had no non-null values, therefore the count is zero.
Similar Messages
-
Acquire an incremental sensor connected on the 6013 board counter with Delphi5
Hi,
I would like to acquire an angular incremental sensor connected on the 6013 board counter with Delphi5. I search an example of Delphi program in order to acquire the measurement of a such sensor. Is there somebody who wrote a such program and who can send to me an example program which works ?.
Thanks a lot.
Best regards.
Vercors
Bonjour,
J'ai
une machine pilotée par un imposant programme en Delphi 5. Je souhaite
instrumenter cette machine avec un capteur angulaire incrémental pour
déterminer la position et le sens de rotation d'un axe. Je souhaite
utiliser le compteur d'une carte multifonctions telle que la 6013 par
exemple. Je recherche donc un exemple d'acquisition d'un tel capteur
par ce type de carte en langage Delphi. S'il vous plait, est ce que
quelqu'un a déjà réalisé un tel programme et pourrait il m'adresser un
exemple dont je puisse m'inspirer. Un grand merci d'avance.
Cordialement.
VercorsBonjour,
Le lien ci-dssous vous explique comment installer des exemples Delphi avec NI-DAQ
How Do I Install Examples for Visual Basic, Visual C++, and Delphi with NI-DAQ?
http://digital.ni.com/public.nsf/websearch/D60BFBC22980F99D862569B6000EF7CE?OpenDocument
En espérant que cela vous aide à construire votre application,
Cordialement,
Benjamin M
NIF -
Need help with NULL values in Crosstables
Hello everybody,
I need some help with NULL values and crosstables. My issue is the following:
I have a query (BW - MDX-Query) that gives me turnover measures for each month. In Crystal Reports I choose crosstable to display this whereby I put all month in columns and all turnover-measures in rows. Each month that has a value (measures are not empty) is chown in the crosstables rows. So far so good. The problem occures when there are month that actually have no values (measures are empty). In that case these months are not chown in columns. But I need CR to display these columns and show the value 0. How can I do that?Hi Frank,
Cross tab shows the data based on your column and these column fields are grouped and based on the group it will show your summaries.
If there is no data for any of your group it will not display that group. In this case you will have to create a standard report which should look like cross tab and to get zero values you need to write formulas .
Example if you want to display Moth wise sales :
if Month() = 01 Then
sum() else 0
Now this formula will check if your month is Jan, then it will sum up the values else it will display zero value.
This is possible only through standard report not with Cross Tab.
Thanks,
Sastry -
i am updating my airport express. However, the message comes up with Invalid value - advertising a service globally using Bonjour requires a global hostname. WHat does this mean?
thank you thank you for taking an interest. this is so frustrating.
i only have apple keyboard, mighty mouse, and 20 inch cinema display connected. this morning took out memory and tried to boot up with individual pairs in the first bank. first the (2)256, the (2) 1g, and then the other (2) 1g modules. everytime I get the weird fuzzy wheel under the logo after a while, black screen flashes, then grey apple logo fuzzy screen then black forever.
I ran tiger updates this morn. still will only boot to safe mode. then tried to run leopard disk to install it
will not boot from leopard disk.
tried safe boot, then doulble click install leopard, restart, then the saga repeats with the pixely red square around the wheel.
these are fresh drives with only what came on instll disk loaded.
thanks again for taking an interest.
i love this system(well at least i did). I want to install leopard on my powerbook too but am terrified to do so right now since it is working and I have work to do. Can't afford to have no computer to do my work on...self employment is great?!
This is making me crazy. I anxiously await your words of wisdom. -
JDBC MS Access--- cannot extract entry with null value with data type Meta
I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
Any advice will be appreciated! thanks!
Following are the table description and JDBC code:
test table has the following attributes:
Field name Data Type
name Text
label Memo
table contents:
name label
me null
you gates
Code:
String query = "SELECT name, label FROM test where name like 'me' ";
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
String name = rs.getString("name");
rs.getString("val");
String label = rs.getString("label");
System.out.println("\t"+name+"\t"+label);
catch (SQLException ex)
System.out.println(ex.getSQLState());
System.out.println(ex.getErrorCode());
System.out.println("in sqlexception");
output:
C:\Temp\SEFormExtractor>java DBTest
yet SELECT name, label FROM test
null
0
in sqlexceptionThe question is how to extract null entry with data type memo?Okay, what you need to do is this:
if (rs.getString("val") == null)
// do something
}This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception. -
How to create a dimension object in SAP BW Unv with Null value
Hello,
for query syncronisation task, I need a dimension object in my BW universe with NULL value. Does someone know, how to do it or if its possible?
Regards,
ThiloHi Thilo,
so the only common item is Material then - correct ?
Query 1 Query 2
Formulation (grouping of materials) (No counterpart)
Material Material
dummy key figure (why?) Company Code
10 Keyfigure
Is this something you regular have to do ? what about a MultiProvider ?
did you try "merged dimensions" in the Web Intelligence Report ?
Ingo -
To overcome column with null value-urgent
hai all,
when i query i get column with null value.
how to solve it?
thank in advance.
rcs
SQL> DESC SCOTT.CB1;
Name Null? Type
ID NUMBER
SUPCODE NUMBER
SUPLNAME VARCHAR2(100)
NAME VARCHAR2(100)
ITEMCODE VARCHAR2(10)
RECDOC NUMBER
RECDATE VARCHAR2(10)
TOTVALUE NUMBER
QTY NUMBER
CB_IPNO NUMBER
CB_VNNO NUMBER
CB_VDT VARCHAR2(10)
CB_AMT NUMBER
RECDOC_GR VARCHAR2(30)
RECDATE_GR DATE
SUPCODE_GR VARCHAR2(10)
TABLE LOOK LIKE THIS (NOT ALL DATA IN SAME ROW, BECUSE I INSERTED LAST 3 COLUMN VALUES):
ID SUPCODE SUPLNAME NAME ITEMCODE RECDOC RECDATE TOTVALUE QTY CB_IPNO CB_VNNO CB_VDT CB_AMT RECDOC_GR RECDATE_GR SUPCODE_GR
2015 AAAA 04117 9083 10545.6 78
2016 BBBB 04609 9087 25200 3600
2017 GGGG 04609 9088 28175 4025
2018 36591371.64 2565017.27
00001/07-08 02/04/2007 14020362
00002/07-08 02/04/2007 14020362
00003/07-08 02/04/2007 14010254
00004/07-08 02/04/2007 14010254
00005/07-08 02/04/2007 14021458
SQL> SELECT DISTINCT ID, SUPCODE_GR, NAME, ITEMCODE, RECDOC, RECDATE_GR, TOTVALUE, QTY FROM SCOTT.CB
1;
ID SUPCODE_GR
NAME
ITEMCODE RECDOC RECDATE_G TOTVALUE QTY
1
PRO.AT.ALU.POWDER UNCOATED
04609 15 51975 7425
2
PEN, GEL PEN
07969 17 154 11
ID SUPCODE_GR
I NEED RESULT AS FOLLOWS (ALL RESPECTIVE DDATA IN ONE LINE NOW NOT LIKE THAT):
ID SUPCODE SUPLNAME NAME ITEMCODE RECDOC RECDATE TOTVALUE QTY CB_IPNO CB_VNNO CB_VDT CB_AMT RECDOC_GR RECDATE_GR SUPCODE_GR
2015 AAAA 04117 9083 10545.6 78 00001/07-08 02/04/2007 14020362
============Even accounting for the formatting, I'm not sure I even understand the question. It could be any number of different problems or non-problems.
-
Sql query slowness due to rank and columns with null values:
Sql query slowness due to rank and columns with null values:
I have the following table in database with around 10 millions records:
Declaration:
create table PropertyOwners (
[Key] int not null primary key,
PropertyKey int not null,
BoughtDate DateTime,
OwnerKey int null,
GroupKey int null
go
[Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
With the following index:
CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]
[PropertyKey] ASC,
[BoughtDate] DESC,
[OwnerKey] DESC,
[GroupKey] DESC
go
Description of the case:
For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
declare @ownerKey int = 40000
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from (
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
) as result
where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
May be the slowness is due to as OwnerKey/GroupKey in the table can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
view.
Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
go
declare @ownerKey int = 1
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from #result as result
where result.[Rank]=1
and result.[OwnerKey]=@ownerKey
go
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
JDBC Receiver Adapter with Null Value
HI,
I have configured ID for JDBC Receiver. In my communication channel, I already check Integration of Empty String Values = Null Value. However, when I check the result from audit log, it still shows that SAP XI sends the null value to database. In my understanding, it should not send the field which has null value (It shouldn't be included in sql statement).
I check this with other scenario. With the same check at Integration of Empty String Values = Null Value, it doesn't send null value to database. It happens only with my first scenario.
Have anyone ever been through this before? Any suggestion please?
Thanks,
PavinHi,
1. The occurrence is 0...1
2. This is the first result with null value (Please see field Error)
UPDATE EXPCRM_T_CustomerProfile SET RequestID=455, RecordNo=1, SAPCustomerCode=0001000344, Error=NULL, Status=2, UpdateDateTime=12/03/2008 13:45:03 WHERE (RequestID=455 AND RecordNo=1)
Then, I change the option from Null Value to Empty string. This is the result.
UPDATE EXPCRM_T_CustomerProfile SET RequestID=455, RecordNo=1, SAPCustomerCode=0001000344, Error=', Status=2, UpdateDateTime=12/03/2008 13:46:12 WHERE (RequestID=455 AND RecordNo=1)
Field Error Change from NULL to '
The expected result from me is that field Error should not exist at all. Please help.
Thanks,
Pavin -
bc4juix:StyledText doesn't work with null values?
Hi , anyone knows why the <bc4juix:StyledText> tag doesn't work with null values?
For example when datasource does not give back data...
Thanks
GuillermoWhich version of Jdev are you using? What are the results you are getting?
-
Range interval partitioning with null value
Hello,
I have question, how can I create table with partition and after that I will insert null value in the partition key like this kind of
range interval partitioning with null value.
I have Oracle 11g.
Thanks
Mohammeduser13777053 wrote:
Thank you, but my question is about range interval not for range?http://docs.oracle.com/cd/E11882_01/server.112/e25523/partition.htm#VLDBG00220
A MAXVALUE literal can be defined for the highest partition. MAXVALUE represents a virtual infinite value that sorts higher than any other possible value for the partitioning key, *including the NULL value.*
So since you're trying to partition by interval (which doesn't support a MAXVALUE clause) you're out of luck.
There's probably fancy hacks and what not you could try to implement, but i'm not about to recommend any of those here :)
Cheers, -
How no to select lines with NULL values
Hi,
I am not a newbie newbie in SQL but I do not understand why I cannot retrieve the lines where there are null values.
The table observatoire.fiche has 2 columns with default values set to NULL : total_heures, and total_heures_exceptionnelles. These are numeric types columns.
I want not to select lines where :
total_heures equal NULL AND total_heures_exceptionnelles = NULLI have tried this but I do get an "Invalid relational operator" error message.
select a.nom || ' ' || a.prenom d, a.agent_id r
from OBSERVATOIRE.AGENT a, observatoire.fiche b
where a.agent_id = b.agent_id
and b.total_heures NOT NULL AND total_heures_exceptionnelles NOT NULL
group by a.nom, a.prenom, a.agent_id
order by a.nomCould you help me ?
Thank you for your kind answers.Satyaki_De wrote:
I think this is not the good way to do it. Did you check my solution? It should work the same output as your solution.Really ?
test@ORA10G>
test@ORA10G> -- (1)
test@ORA10G> with t as (
2 select 1 as x, 10 as total_heures, null as total_heures_exceptionnelles from dual union all
3 select 1, null, 20 from dual union all
4 select 1, null, null from dual union all
5 select 1, 30, 40 from dual)
6 --
7 select x, total_heures, total_heures_exceptionnelles
8 from t
9 where x = 1
10 AND NOT ( total_heures IS NULL
11 AND
12 total_heures_exceptionnelles IS NULL
13 );
X TOTAL_HEURES TOTAL_HEURES_EXCEPTIONNELLES
1 10
1 20
1 30 40
test@ORA10G>
test@ORA10G> -- (2)
test@ORA10G> with t as (
2 select 1 as x, 10 as total_heures, null as total_heures_exceptionnelles from dual union all
3 select 1, null, 20 from dual union all
4 select 1, null, null from dual union all
5 select 1, 30, 40 from dual)
6 --
7 select x, total_heures, total_heures_exceptionnelles
8 from t
9 where x = 1
10 AND total_heures IS NOT NULL
11 AND total_heures_exceptionnelles IS NOT NULL;
X TOTAL_HEURES TOTAL_HEURES_EXCEPTIONNELLES
1 30 40
test@ORA10G>
test@ORA10G>isotope -
Pro*C & SQLDA with NULL value for predicate column
Hi: I am using a C program to update a table via a dynamic sql (method 4) and SQLDA. In the update statement predicate, I have place holders (as in TBLCOL=:C000). One of the columns in the predicate contains null values, so I set L[n] = 0, V[n] = pData (which pData[0] = '\0'), *(I[n]) = -1, and T[n] = 5 (for text). I cannot find the row that I know is there.
I cannot change my statement to contain TBLCOL IS NULL, since I don't know ahead of time if I'm looking for rows with null values for this column. The Pro*C manual says that by setting the appropriate *(I[n]) = -1, it indicates to Oracle to simulate the "IS NULL" clause, and update the appropriate rows. In my case, I receive 1403 as SQLCODE when I use TBLCOL=:C000 vs TBLCOL IS NULL. What am I doing wrong? Thank you for your help.You should include these columns as well;
ChangeType (see mxi_changetype)
ValOwner (repository)
UserID ("jobid=<>", usermskey, GUI (mmc), DG (dyngrp), reconcile)
IdAudit (This is the event task (add and del member for assignments)
ParentAuditId (AuditID of parent which last updated the attribute, not consistent)
ChangedBy (Holds the MSKEY of the user which last changed the attribute)
ExpiryTime
to make sure you get a fuller picture of the audit record.
Your selection does not cover all events and descriptions
br,
Chris -
Clarification needed in the Fault Handling Framework(Error Hospital)
Hi,
I need some clarification on Fault Handling Framework...
Scenario:
My BPEL Process is Asynchronous.(10.1.3.3.1) and I tryed to invoke the another BPEL Process( which is used to select the Fname from the table using DB Adapter) . In the Main BPEL Process I have the Fault handling Framework and I done necessary changes in the bpel.xml. This is successfully working for Invoke Activity when ever an Remote or Binding Fault occurs in the Sub-BPEL Process and this Fault is send to Fault-Policy.xml in the server(bpel/domains/default/config/fault-Policy) and works accordingly to the action mentioned in the policy xml....( I have also made changes in the fault-bindings.xml ).
How ever this Framework is working fine for every actions.
Need Clarification:
1) Only the Binding and Remote faults will work for the Fault handling Framework.
2) can we use User defined faults (Buissness Faults,,,) for this........because I used the User defined faults to invoke the fault-policy.xml and it won't works....
3)Only Invoke Activity can be handled for this Framework or any Other Activity........
4)How to handle other Activity in the Fault-policy.xml...
5)Any difference for Asynchronous or Synchronous in this Fault Handling Framework.......
I also referred the Oracle SOA Suite New Feauters PDF .......
Can any one send me the related documents and try to help me on this.
Please help me on this.......
Thanks,
Ashok.Hi Chintan,
You are saying that Custom faults are also supported for fault-Policy.xml.
I can't understand that 2nd answer you said. can you please explain how to use the Custom faults in the FaultHandlingFramework..
My Scenario:
I have 2 BPEL Process, BPEL1 will invoke the BPEL2 and if any remote fault or binding faults occurs in the BPEL 2 its returning the same fault to BPEL1 and here I am using FaulthandlingFramework , this fault send to fault-policy.xml and necessary action is took place succesfuly...(like retry, human intervention.....)
But when I throw some CustomFaults(userdefinedFaults)in the BPEL2 , its returning as a remotefault to BPEL1. I don't know how to use the customFaults in the Fault handling framework.......
Can you explain me in detail how to use custom faults in faulthandling framework...............
Send me some related documents for this..... -
Help Needed: Facing the error ORA-01406: fetched column value was truncated
Hi Everyone,
When I run a particular PL/SQL query using Oracle 9i ODBC driver, it is working fine and fetching me the desired results.
However, when I run the same query using the Oracle 10g ODBC driver, I am getting the error: ORA-01406: fetched column value was truncated.
I have checked all the fields of the table and they are well within the allowable limit.
Can you please let us know what needs to be done to resolve this issue?
Thanks and Regards,
SudhindraWell it's obviously a problem with the client software. Doesn't Datastage have some way of configuring these things?
rgds, APC
Maybe you are looking for
-
Hi SAP Guru s I am facing a dump when i pass the Gt_sort in reuse alv display FM I am tryingto display the subtotals on the kunnr for dollars and count via ALV following is the code ur advice is highly appreciated thanks report orders .
-
Please help
-
I put the wrong birthdate when registering my daughters new iPod Touch. It didn't let me establish a new account because the birthdate was too young. When I went to correct it, it continued the lock her new registration out. Now I can't successfully
-
Tableview disappears on row-selection
hi all, the data in my tableview is huge and if i try to select any row, the tableview completely disappears for a long time and when it appears, the row remains unselected. Same thing happens for any other event on tableview like scrolling through i
-
Satellite A300-1AK don't start after update Win Vista
Hello everyone, hope someone can help me I have a toshiba notebook with a view, I got the bright idea to do an update since a long time that was not updated at the end. I restarted the update as required nb. and then nothing! The practice turn on the