Count the numbers in a column??
Hi Guys!!
I have a column in a table:
Number
100
2
1
19
2
11
27
14
28
12
9
12
54
72
1
17
I want to calculate how many of those are:
Less than 50,
50 to 99,
100 to 149,
149 to 199 and like that.......Plz suggest me the Query.
Cheers,
AP
Suppose you have a table T with column N.
SQL> select * from t;
N
5
10
15
50
60
70
75
80
85
95
SQL> select trunc((n-1)/50)+1,count(*)
2 from t
3 group by trunc((n-1)/50)+1
4 /
TRUNC((N-1)/50)+1 COUNT(*)
1 4
2 6
where 1 is for values from 0-50, 2 for 51-100 and so on.
Anwar
Similar Messages
-
Count the items in a column with multiple values?
Hi all
Is there a way to count the items in a column that allows multiple values?
Example list:
Course title: Participants:
Visual Basic Introduction John Smith; Lois Lane; Clark Kent
Visual Basic Advanced John Smith; Lex Luthor
The result should be "3" and "2" (number of participants), which should be displayed in the list or on the page.
Is this possible?
( I am using Sharepoint 2007 and have access to Sharepoint designer.)
Thanks!Hi dee,
We can use XSLT to do this in Data View Web Part.
First, display your list in data view web part.
Insert a new column in the data view, used to display the count.
Switch to code mode, add following code within the <td></td>.
<td>
<xsl:choose>
<xsl:when test="@Title!=''">
<xsl:variable name="count">
<xsl:call-template name="countChar">
<xsl:with-param name="str" select="@Title" />
<xsl:with-param name="count" select="1" />
</xsl:call-template>
</xsl:variable>
count is <xsl:value-of select="$count" />
</xsl:when>
<xsl:otherwise>
count is <xsl:value-of select="0" />
</xsl:otherwise>
</xsl:choose>
</td>
And put the following template definition outside all the other templates.
<xsl:template name="countChar">
<xsl:param name="str" />
<xsl:param name="count" />
<xsl:choose>
<xsl:when test="contains($str, ';')">
<xsl:call-template name="countChar">
<xsl:with-param name="str" select="substring-after($str, ';')" />
<xsl:with-param name="count" select="number($count) + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$count" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Done and then you will see the count in the td cell.
I test with Title column and cut off string with ";" character.
Thanks & Regards,
Emir Liu
TechNet Subscriber Support in forum
If you have any feedback on our support, please contact [email protected]
Emir Liu
TechNet Community Support -
How do you count the number of returned rows in CF? Note not
the number
of the row, but the the order by number of each row returned.
Thanks in advance.I dont think I quite understand your question, but...
#queryname.RecordCount# gives the total number of rows
returned.
#queryname.CurrentRow# gives the row number you are working
on. -
Table monitoring , how do oracle count the numbers ?
hi,
i'm looking at all_tab_modifications , just couldn't figure out where those numbers from ,
DB.9208 , table partitioned
looks like it off of what it should be
my question is
1. when does montioring take place , and by how?
2. is the number cumulative from monitoring turn on ? from instance restart ? or between two snaps ?
3. offical doc says like inserts is Approximate number of inserts since the last time statistics were gathered
that means the number recycles after snap taken , it goes on by every DML , but i have insertions against a table which says inserts is 0
4. some says to reflect the newest exec dbms_stats.flush_database_monitoring_info; which is even more confusing for me and makes no difference in my case
thanks
TABLE_NAME INSERTS UPDATES DELETES TIME
T_GB_RA_PAGING 0 0 2372389 20081125 005005
T_IU_OVERLOAD 0 0 0 20081125 005005
T_RAUM 0 0 13963245 20081125 005005
T_GB_SGSN_DATA 0 0 33283 20081125 005005
T_IU_SGSN_DATA 0 0 0 20081125 005005
T_SESSION_MANAGEMENT 82 0 386950042 20081125 005005
T_DATA 82 0 1595707 20081125 005005
T_USER 82 0 112562 20081125 005005
T_MOBILITY_MANAGEMENT 82 0 515890902 20081125 005005
T_DIPN 82 0 0 20081125 005005
T_RAUM 22409 0 0 20081125 103237
T_SESSION_MANAGEMENT 365547 0 0 20081125 103237Edited by: zs_hzh on Nov 24, 2008 10:35 PM1. when does montioring take place , and by how?When you create a table, by default, it is set in MONITORING mode.
SQL> create table testtable as select * from all_objects where 1 = 2;
Table created.
SQL> select monitoring from user_tables where table_name='TESTTABLE';
MON
YES
2. is the number cumulative from monitoring turn on ? from instance restart ? or between two snaps ?http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2097.htm#i1591024
<quote>
ALL_TAB_MODIFICATIONS describes tables accessible to the current user that have been modified since the last time statistics were gathered on the tables.
<quote>
3. it goes on by every DML , but i have insertions against a table which says inserts is 0Is your table in MONITORING mode? If not, there will be no records in this view for that table.
4. some says to reflect the newest exec dbms_stats.flush_database_monitoring_info; which is even more confusing for me and makes no difference in my caseIt could be related to answer for #3.
Refer to this small demonstration.
SQL> execute dbms_stats.gather_table_stats(user,'TESTTABLE');
PL/SQL procedure successfully completed.
SQL> select * from all_tab_modifications where table_owner=USER and table_name='TESTTABLE';
no rows selected
SQL> insert into testtable select * from all_objects;
55958 rows created.
SQL> commit;
Commit complete.
SQL> select * from all_tab_modifications where table_owner=USER and table_name='TESTTABLE';
no rows selected
SQL> execute dbms_stats.flush_database_monitoring_info;
PL/SQL procedure successfully completed.
SQL> select table_name, inserts from all_tab_modifications where table_owner=USER and table_name='TESTTABLE';
TABLE_NAME INSERTS
TESTTABLE 55,958
SQL> insert into testtable select * from all_objects;
55958 rows created.
SQL> select table_name, inserts from all_tab_modifications where table_owner=USER and table_name='TESTTABLE';
TABLE_NAME INSERTS
TESTTABLE 55,958
SQL> execute dbms_stats.flush_database_monitoring_info;
PL/SQL procedure successfully completed.
SQL> select table_name, inserts from all_tab_modifications where table_owner=USER and table_name='TESTTABLE';
TABLE_NAME INSERTS
TESTTABLE 111,916 -
I'm using Numbers 3.2 and would like to count the names in a column which satisfy a condition in a different column. There are 3 "streams" through which these names have come to me, and I would like to easily identify how many have come from each stream. Any help?
Hi DirtyDawg,
COUNTIF is your friend here.
If your source is in column C and your streams are 1, 2 and 3:
=COUNTIF(C,"=stream1")
=COUNTIF(C,"=stream2")
=COUNTIF(C,"=stream3")
These need to be in a footer or header row or in a different column than C.
hope this helps,
quinn -
Count the number of rows based on the values!!!
Hi all,
What I am using:
I am working with a multidimensional database in Visual Studio 2010 using its Data source view and calculation member and dimension usage.
What I want to do:
I have a fact table that has five columns(leg(s),hand(s), Head and body,overall) that shows the category of how severe the injury is. Let say for the records all columns never have an empty value(no injury is stated with 'No injury' ) . These five columns
are connected with a dimension that has all the available values (Category A-E of injury).The overall has the most severe from the other four columns. I want to create a bar chart with five different measure
values, one for each column, and count the values in those columns.
For example : I have a slicer in the excel and a bar chart and the slicer has all the values of the Category of the injury ( Cat a,Cat B, Cat C, ... Cat E, No injury ) and when i select one of them, lets say
Cat C, the bar chart should update and show how many Cat C each measurement column has.
Example FACT table:
ID LEG HAND HEAD BODY OVERALL
1 No A No No A
2 No D C C C
3 E C D A A
4 E E B C B
So if i selected C the bar chart will count (Leg = 0, Hand = 1, Head = 1, body = 2 and Overall = 1).
Any ideas ?
Thanks for the help and the time :)Hi DBtheoN,
According to your description, you want to create a chart on excel worksheet to count the rows based on the value, right? If in this case, I am afraid this issue is related to Office forum, I am not the expert of Office, you can post the issue on the corresponding
forum.
However, this requirement can be done easily on SQL Server Reporting Services. You can using the expression below to count the rows.
=COUNT(IIF(Fields!LEG.Value=Parameters!TYPE.Value,1,NOTHING))
Regards,
Charlie Liao
TechNet Community Support -
How to count the pulses of an incrementa​l encoder with PCI-6010?
Hi everyone,
I am trying to use an incremental encoder and PCI-6010 card to measure the speed of a rotary shaft in Labview 2011. I need to use the counter to count the numbers of the pulses that the encoder generates but I have some problems there to do so.
I connected the encoder signal to the counter source (PFI0) and built a daq assistant block in the Labview (Acquire signals -> Counter Input -> Edge Count -> ctr0) and it is set as shown in the figure. The problem is that no matter how I turn the shaft the measured value will always be 0 although the pulses can be seen very clearly on the O-scope.
I suppose I must have made a very simple mistake. Could anyone help me on that please?
Thank you.Hi YShZh,
The current Acquisition Mode setting is set to "1 Sample (On Demand)" and will therefore only ever give you the first count value. The fist count value is equal to the initial count value, which in your case is 0.
Try changing the acquisition mode to either N Samples or Continuous Samples.
Kind regards,
Marshall B
Applications Engineer
National Instruments UK & Ireland -
ITunes 11 couldn't count the number of your music at bottom? Help
why now iTunes couldn't count the numbers or the whole time to play the music at the below part of iTunes just like old version used to do?
Go to View > Show Status Bar
-
How do I count the unique value pairs in two columns of a table?
I have a table (Table 2) that is populated with data from an imported .csv file. On table 1 I need to count the unique value pairs in two columns of Table 2.
Here's what I have:
Date Person
7/10/2011 A
7/12/2011 W
7/12/2011 X
7/12/2011 X
7/12/2011 X
7/12/2011 Z
7/14/2011 Z
7/15/2011 X
7/16/2011 Z
I'm focusing on person "X" and can easily count how many days that person shows up but what I want is to see on how many unique days that person shows up.
Here's the result I'm looking for (Person "X" shows up on 2 different days - 3 times on 7/12/2011 and once on 7/15/2011):
X 2
I can't seem to find a function that allows me to do that. I also am not allowed to modify Table 2 so that leaves me to come up with a solution on Table 1.
Any ideas would be greatly appreciated.Hi John,
Not being allowed to modify Table 2 is a minor inconvenience. Just copy (using a formula) the necessary two columns onto Table 1.
Yellow columns may be hidden. The procedure progresses from left to right. All formulas are entered into row 2 then filled down that column to the end of the table. The table must be as long as the list in column A of Table 2.
A2: =Table 2::A
Fill right to column B.
Fill both columns down as far as needed.
I've used actual Date and Time values in column A, formatted to show only the Date part, but the technique will work with text in these cells, provided all cells representing the same 'date' have exactly the same content.
C2: =A&B
This concatenates the contents of each row of columns A and B into a single text string.
D2: =COUNTIF($C$2:C2,C)
This counts the number of occurrences of the Date&Name string on the current row from the first regular cell in column C (C2) to the current cell.
E2: =IF(COUNTIF($B$2:B2,B)=1,MAX($E$1:E1)+1,"")
This constructs the index of first occurrences of each name, in the order they first occur. The index is used by LOOKUP in column F.
F2: =IF(ROW()-1>MAX(E),"",LOOKUP(ROW()-1,$E,$B))
This uses the index value created in E as a search-for value to extract a single copy of the names in column B. The result is a list of all distinct names in the list. Note that spelling differences will be counted as distinct names.The IF statement stops the listing when the last distinct name is extracted.
G2: =IF(LEN(F)>0,COUNTIFS($B,"="&F,$D,"=1"),"")
This counts the number of 'first occurrences of distinct Date & Name strings for each name on the list (ie. the number of distinct dates on which each name appears in the original list).
All of the functions used are described, with at least one example for each, in the iWork formulas and Functions User Guide. You can download the guide, and the Numbers '09 User Guide, via the Help menu in numbers.
Regards,
Barry -
How do I count the unique text entries in a column
I want to count thenumber of unique text entries in a column how do I do that?
Or, if you will need to do this on different documents, you can copy this script into AppleScript Editor, select the cells in whichever document you are working on, and run. No need to set up the formulas and extra column again.
SG
--select range of cells, run; provides count of distinct values
tell application "Numbers" to tell the front document to tell active sheet
set selectedTable to (the first table whose class of selection range is range)
tell selectedTable to tell the selection range
set distinctValues to {}
repeat with aCell in its cells
tell aCell
if its value is not in distinctValues then ¬
copy its value to the end of distinctValues
end tell
end repeat
return count of distinctValues
end tell
end tell
--end of script -
Count the displayed date rows on a column.
Hi,
I am trying to have a table with the following information and try to give a total count (of the dates visible) at the bottom of the table for the date columns. (not counting the rows)
(E.g.- Under the Sent column there are 5 dates displayed and there are 6 numbers associated. On the received column there are 3 dates displayed for 6 numbers)
Could you please advice me how to accomplish this. Thank you in advance.
Rob.
Name SENum SentReceived
John 1234 12/22/06
5678 12/13/06
6565 12/19/06 1/6/07
5656 - -
Jane 9866 12/18/06 1/5/07
Jim 5657 12/18/06 12/14/06
Total: 5 3I ma not sue what you want but
here is some idea at sql plus
SQL> compute count of ename on deptno
SQL> compute count of sal on deptno
SQL> select deptno,ename,sal from emp order by deptno
2 ;
DEPTNO ENAME SAL
10 CLARK 2450
KING 5000
MILLER 1300
count 3 3
20 SMITH 880
ADAMS 1100
FORD 3000
SCOTT 3000
JONES 2975
count 5 5
30 ALLEN 1600
BLAKE 2850
MARTIN 1250
JAMES 1045
TURNER 1500
WARD 1250
count 6 6
DEV 5000
count 1 1 -
Count the number of unique values in column
Hi
I have a large numbers file (thousands of rows) with data for different dates. I need to calculate the number of unique (distinct) dates are in the spreadsheet.
Does anyone know how to do this?
Thanks,
Brucebpj,
Let's say your date is in column B for this example and your first data row is Row 2. In another column you can enter into row 2: =IF(COUNTIF($B$2:B2, B)=1, 1, "") Summing the new column content will yield the number if unique dates.
As badunit observes, this will result in sluggish document. If the number of possible dates is small compared to the number of rows of data, it would be better to make a table of possible dates and count the number of occurrences of each of those dates in the data, a COUNTIF function on the frequency data for the date range will give you the number of unique dates, possible much more efficiently.
Jerry -
How to count number of rows as well as the sum of a column in a procedure
Hi, i need to count the number of rows a sql returns in a procedure.
as well as i need to sum up a different column.
i need the following output:
count the number of rows output
and sum the total column
code:
procedure samba_extraction (p_errmsg IN out varchar2
,p_errcode IN out NUMBER
,p_filename in varchar2
,p_start_date varchar2
,p_end_date varchar2)
is
file_handle utl_file.file_type; -- file handle of os flat file
-- cursor to select the c_samba_resources
cursor c_samba is
select
lpad(h.contract_number,15,'0') contract_number
,h.short_description description
,h.attribute_category context_value
,h.attribute7 samba
,h.attribute8 samba_number
,h.start_date start_date
,h.end_date end_date
,h.sts_code active_inactive
,l.price_negotiated price
,l.tax_amount tax
,LTRIM(to_char((l.price_negotiated + l.tax_amount),'00000000.00')) total
from
oks_auth_headers_v h
,oks_auth_lines_v l
where h.id = l.chr_id
and ((h.start_date <= (p_end_date))
and (h.end_date >= (p_start_date)))
and h.attribute7 = 'SAMBA'
-- and h.sts_code = 'ACTIVE'
and ((h.attribute_category = 'SUBSCRIPTION.DURATION')
or (h.attribute_category = 'SUBSCRIPTION.VALUE')
or (h.attribute_category ='SUBSCRIPTION.QUANTITY'));
l_output varchar2(1000);
l_counter varchar2(11);
l_total varchar2(11);
l_filename varchar2(30);
begin
if p_filename IS NOT NULL then
-- l_batch_no := 'T';
l_filename := p_filename || '.txt';
-- open file to write into and obtain its file_handle.
file_handle := utl_file.fopen('/usr/tmp',l_filename,'W');
fnd_file.put_line(fnd_file.log,'The '|| l_filename||' file you have requested has been placed in the usr/tmp directory');
for l_info in c_samba
loop
-- l_output := null;
l_output := l_info.samba_number||'+'||l_info.total||l_info.contract_number;
utl_file.put_line(file_handle,l_output);
fnd_file.put_line(fnd_file.output, l_output);
dbms_output.put_line(l_output);
end loop;
else
p_errmsg := ('Please enter a filename for this file ');
write_log('UPDATE : ' ||p_errmsg);
end if;
-- close the file.
utl_file.fclose(file_handle);
exception
when no_data_found then
dbms_output.put_line('no_data_found');
utl_file.fclose(file_handle);
when utl_file.invalid_path then
dbms_output.put_line('UTL_FILE.INVALID_PATH');
utl_file.fclose(file_handle);
when utl_file.read_error then
dbms_output.put_line(' UTL_FILE.READ_ERROR');
utl_file.fclose(file_handle);
when utl_file.write_error then
dbms_output.put_line('UTL_FILE.WRITE_ERROR');
utl_file.fclose(file_handle);
when others then
dbms_output.put_line('other stuff');
utl_file.fclose(file_handle);
end samba_extraction;
end xx_samba;Hi,
Initialise one variable TOT_ROWS to 0.
Then in the for loop
tot_rows := tot_rows + +1 ;
so after for loop the value in the tot_rows will be the total records..
If u want it to get this value in the calling procedure of this , just declare tot_rows parameter as out parameter.
For sum of a column:
Initialise a variable sum_col to 0.
In the for loop
sum_col := sum_col+I_info.column_name
aprameter if u wish return this value as out..
I think this wil give u the o/p..
cheers,
Sivarama -
Count of schema based on the value in a column
I have to write a query to count the number of schema that have the value in a column as '1' in a table For ex
I have a table called Vendor in all the schemas(schema1 through 50) I have to look for the value in a column(Benefits) if it 1 or 0 . I need to do the count of the number of schema who have the Benefits turned ON (value '1')
suppose the value in benefits(col) in Vendor (tbl) for schema1 is 0 than donot count that schema
and if the value in benefits(col) in Vendor (tbl) for schema2 is 1 than count
do i connect as a system manager? Do I need a Pl/sql table to put the count in it
anybody please help.
TX
KKAs I understand from 325537 description, the table VENDOR contains only one row and column BENEFITS_TRACKING is either 0 or 1
In this case the total can be calculated by simply summing the values of all BENEFITS_TRACKING
In case VENDOR has more than one row you need some grouping function like SUM or COUNT
I don't unterstand why you loop through dba_users.
Im quite sure that you won't find a VENDORS table in the SYSTEM schema. The 'execute immediate' will fail with a table not found exception.
Another problem in your code is, you will get no_data_found exception when benefits_tracking=0 because of your where condition
(remove the where-condition or use a grouping function as explained above)
declare
v_count pls_integer := 0;
v_curr_count pls_integer := 0;
begin
for rec in (select owner from all_tables where owner like 'SCHEMA%' and table_name='VENDORS') loop
execute immediate 'select SUM(BENEFITS_TRACKING) from '||rec.owner||'.VENDORS' into v_curr_count;
-- execute immediate 'select COUNT(BENEFITS_TRACKING) from '||rec.owner||'.VENDORS where BENEFITS_TRACKING=1' into v_curr_count;
-- execute immediate 'select BENEFITS_TRACKING from '||rec.owner||'.VENDORS' into v_curr_count;
v_count := v_count + v_curr_count;
end loop;
dbms_output.put_line(v_count);
end; -
Count the no. of rows in a column
I want to count the no. of rows in APR_QTY column that are not equal to zero.
SELECT DISTINCT
SUPP_NAME,
ITEM_NAME,
(CASE WHEN BH_CAL_PERIOD=4 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)APR_QTY,
(CASE WHEN BH_CAL_PERIOD=4 THEN BI_RATE ELSE 0 END)APR_RATE,
(CASE WHEN BH_CAL_PERIOD=5 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)MAY_QTY,
(CASE WHEN BH_CAL_PERIOD=5 THEN BI_RATE ELSE 0 END)MAY_RATE,
(CASE WHEN BH_CAL_PERIOD=6 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUNE_QTY,
(CASE WHEN BH_CAL_PERIOD=6 THEN BI_RATE ELSE 0 END)JUNE_RATE,
(CASE WHEN BH_CAL_PERIOD=7 THEN TO_NUMBER(BI_QTY || '.' || BI_QTY_LS) ELSE 0 END)JUL_QTY,
(CASE WHEN BH_CAL_PERIOD=7 THEN BI_RATE ELSE 0 END)JUL_RATE
FROM
OM_SUPPLIER,
OM_ITEM,
OT_BILL_HEAD,
OT_BILL_ITEM,
OT_BILL_ITEM_TED
WHERE BI_BH_SYS_ID = BH_SYS_ID
AND SUPP_CODE = BH_SUPP_CODE
AND ITEM_CODE = BI_ITEM_CODE
AND BH_SYS_ID = ITED_H_SYS_ID
AND BI_SYS_ID = ITED_I_SYS_ID
AND BH_TXN_CODE='SBRLRAW'
GROUP BY BH_CAL_PERIOD,BH_TXN_CODE,SUPP_NAME,ITEM_NAME,BI_RATE,BI_QTY,BI_QTY_LS
ORDER BY ITEM_NAME
Message was edited by:
yogeshylSelect sum(decode(apr_qty,0,0,1)) as cnt_apr_qty
from ...
Maybe you are looking for
-
Oracle 8.1.7 on Red Hat 7 works (here's how)
Thanks to Richard Rankin's post, I was able to get Oracle 8.1.7 working with Red Hat 7.0. It even works with the 2.4.0 kernel. Since there have been so many posts regarding this problem, I have copied Mr. Rankin's post again below: 1) Load the Redhat
-
Cannot reformat my disk to install SL on a new internal HDD
Bought a new 1 TB HDD as my pother disk drive was getting to full and decided not to work. When i try to repartition the disk i get the error message POSIC reports: the operation couldn't be completed cannot allocate memory When i try to erase the cu
-
ByteArray to String and String to ByteArray error at readUTF from datainpu
hi everybody this is my first post I hope I can find the help I need I have been doing some research and couldnt find the solution thanks in advanced The Objective: im building a client server application with java and I need to send a response from
-
Partitioning Lion and Snow Leopard
I've tried following the instructions other people have posted about this to no avail. I'm on a 17" MacBook Pro with 2.8 GHz Intel Core 2 Duo. The only reason I bought Lion was to run Avid MC6. It's rubbish, so I want to reinstall Snow Leopard and ru
-
How do I get rid of license agreement screen?
Everytime I try to access photoshop CC the license agreement screen pops up. No matter how many times I press accept it still continues to pop up. It worked well after I installed it, but it just now started acting like this.