How to Count number of rows
Hi All
If I have 2 tables with records in it, with primary Table A and Foreign key Table B structure.Then how to count the no of occurances of each records of table A in table B and print the values.
Thanx
Hi,
If I understood you can a query like this:
SGMS@ORACLE10> create table a (cod number);
Table created.
SGMS@ORACLE10> create table b (cod number,id number);
Table created.
SGMS@ORACLE10> alter table a add constraint pk_a primary key (cod);
Table altered.
SGMS@ORACLE10> alter table b add constraint fk_b_a foreign key (cod) references a;
Table altered.
SGMS@ORACLE10> insert into a values (1);
1 row created.
SGMS@ORACLE10> insert into a values (2);
1 row created.
SGMS@ORACLE10> insert into a values (3);
1 row created.
SGMS@ORACLE10> insert into b values (1,1);
1 row created.
SGMS@ORACLE10> insert into b values (1,2);
1 row created.
SGMS@ORACLE10> insert into b values (1,3);
1 row created.
SGMS@ORACLE10> insert into b values (2,1);
1 row created.
SGMS@ORACLE10> insert into b values (3,1);
1 row created.
SGMS@ORACLE10> insert into b values (3,2);
1 row created.
SGMS@ORACLE10> commit;
SGMS@ORACLE10> select b.cod,count(*) from b,a where a.cod = b.cod group by b.cod;
COD COUNT(*)
1 3
2 1
3 2
SGMS@ORACLE10>Cheers
Similar Messages
-
How to count number of rows in table
can I get number of row in table except Count(*) in pl/sql
is there any other wayAlso posted and answered here
how to count number of rows in table
count(*) will be the fastest way. It is only slow if the table has a vast number of rows, in which case why do you need to know the tables has 73552436467721 rows and not 73552436467737 rows. It doesn't seem to be much use. Either that or you are counting them a lot, which again seems rather pointless. -
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 -
How to count number of rows in a cursor???
I have a cursor and i want to check number of row fetched...But not through rowcount... bcoz it will give after fetching all the rows..
I want to get count as soon as i open the cursor..plz let me knowDavid_Aldridge wrote:
hmmm ... you'd have to wrap the query in an inline view and apply the count(*) over() in the main query I guess.Still will not cover all cases:
Session 1:
update emp set deptno = deptno where deptno = 20
5 rows updated.
SQL> Session 2:
select ename,
count(*) over()
from emp
for update
skip locked
ENAME COUNT(*)OVER()
ALLEN 14
WARD 14
MARTIN 14
BLAKE 14
CLARK 14
KING 14
TURNER 14
JAMES 14
MILLER 14
9 rows selected.Now try to wrap the above query in an inline view :).
SY. -
How to get number of rows return in SELECT query
i'm very new in java, i have a question:
- How to get number of rows return in SELECT query?
(i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
Thanks.make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
String sql = "select * from testing";
PreparedStatement ps =
con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = ps.executeQuery();
rs.last();
System.out.println("Row count = " + rs.getRow());
rs.beforeFirst();~Tim
NOTE: Ugly, but does the trick. -
Need help to count number of rows and display in file
Hello,
my scenario is IDOC to File......i am using XSLT mapping and using FCC parameters to convert the flat file.
now new requirement is i need to count number of rows and add count value last of the file.
Please let me know how to do it,
thanks in advance for your help.
Regards,
Chinnathanks again, one more Q.
in XSLT mapping i have written for loop for complete structure.
example : <Details>
<node1>
<node2>
</details>
in XSLT mapping
<xsl:for-each select="ZMATMAS_01/IDOC/E1MARAM">
<Details>
</Details>
</xsl:for-each>
if i add the field at target side....then i will come under details node and it will be repeated.
how to declare in XSLT mapping. -
How to display number of rows as columns in a select statement? This is on
How to display number of rows as columns in a select statement? This is on 10g R2.
Thanks,
RFor the current (ie. row 1 of 100)
row_number over (order by -pick_a_column_set) as rnfor the total number of columns returned in your query
count(*) over() as total_count -
Hi!
1. How can you through ABAP and select statements count the number of rows in one table?
2. I want to read all rows from one table to an internal table. Can this be done dynamically or do I first have to count the number of rows in the table and then declare an internal table with the number of rows counted.
regards
BaranHI,
No you don't have to count number of rows first, Internal table size will increase dynamically. you have to declare this with initial size like this.
<b>data: itab type standard table of bkpf initial size 0.
SELECT * FROM bkpf into table itab.</b>
All values from bkpf will be inserted into table internal table itab.
Regards, -
How to count number of sales orders generated in a month in SAP SD
Hi SD Gurus,
I have a very strange query from client. I have to count the number of sales order created in a month for a z report. For example 30 in Jan, 25 in Feb etc. Could anyone suggest me How to count number of sales orders generated in a month in SAP SD.
Regards
Vinod KumarHi,
Goto the T.Code "SE16" or "SE16n" or "SE11".
Enter the table name as VBAK
Enter the created on date as the starting date of the period and to date as the end date.
Enter.
Click on "Number of Entries".It will tell you the number of entries created in a particular period.
If you want a report,goto the T.Code "VA05n".
Regards,
Krishna. -
How to restrict number of rows display using ig:gridView
Hi
All
How to restrict number of rows display using <ig:gridView datasource="{mybean.mylist}">
i am getting 10 rows using data_row . i wanna show only first 5 rows .
pageSize ="5" will be ok . but it displays remaining rows in next page. but i want to display only first 5 rows . is there any attribute to restrict number of rows.
thanks
rambhapuriI have no idea which component you're talking about. If want to discuss here about a non-Sun JSF component, then please mention about the name, version and build in detail. You can also consider posting this question at the website/forum/mailinglist of the component manfacturer rather than here. At least I can tell you that the Sun JSF h:dataTable has the 'rows' attribute for that. I can also suggest you to just take a look in the TLD documentation of the component in question. There should be all possible attributes listed with a detailed explanation about the behaviour.
-
How to calculate number of rows for perticular characterstic in SAP BI Bex
Hi experts,
Please let me know how to calculate ' number of rows ' for perticular characterstic in Bex query.
Thanks & Regards,
Babu..Hello,
You can try this
Create a CKF and assign the vale 1 to it. Open the query and select Character where you want to display ' number of rows ', go to properties windows, select 'display', in the results row drop down box, select 'always display'.
Thanks.
With regards,
Anand Kumar -
How to Count Number of completed line items in past 6 months / 12 months ?
How to Count Number of completed line items in past 6 months / 12 months ?
Hi,
I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
Purchase Order document = ZEBELN
Line Item = ZEBELP.
I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
I have "Delivery Completed" field, ELIKZ.
So, based on this would I be able to calculate it in Query Designer?
If so, Please let me know howHello Deva
If youe want to calculate the completed line item for last 6 or 12 month then i think u will be displaying the query data for these montrhs...create a customer exit to give you date range and restric it in filter area....
Now Choose any of the below option
1. I would suggest to implement an additional key figure "counter" in cube and fill values with one for which delivery is completed.
Now use calculated key figure in Query Designer based on logic
IF counter = 1 THEN counter ELSE 0
OR
2. create a formula variable based on ELIKZ and use replacement path variable, it will display you no. of docs for which delivery is completed....
Award points if it solves your problem
Revert back in case of further assistance...
Thanks
Tripple k -
How to count number of ones in table
Hello,
i created one table 16x32 each cell is updating 1 byte of data,how to count number of one in all cell,and is it right way to calculate check sum??
thank youThe simplest way is to call GetTableCellRangeValues with VAL_ENTIRE_TABLE as the range, next summing array elements.
But I don't understand your comment on checksum, so this may not be the more correct method for your actual needs: can you explain what do you mean?
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
How to count number of online user
i am developing bid application using servlet/jsp. how to count number of online user ple help me.
hi,
may be the following code help you...
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class ActiveUserCount implements HttpSessionListener {
private static int activeUsers = 0;
public void sessionCreated(HttpSessionEvent se) {
activeUsers++;
public void sessionDestroyed(HttpSessionEvent se) {
if(activeUsers > 0)
activeUsers--;
public static int getActiveUsers() {
return activeUsers;
}Dhaval -
Please let me know how to Count Number of completed line items in past 6 mo
How to Count Number of completed line items in past 6 months / 12 months ?
Hi,
I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
Purchase Order document = ZEBELN
Line Item = ZEBELP.
I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
I have "Delivery Completed" field, ELIKZ.
So, based on this would I be able to calculate it in Query Designer?
If so, Please let me know how
KrishnaHi Experts,
I dont have a defined Restricted key figure yet.
I have populated 0COMPL_DEL(Delivery Completed Indicator) and 0EBELN (Purchasing Document Number) and 0EBELP (Line Item Number in Purchasing Document) .
This is what I think how I need to calculate:
Number of completed line items in past 6 months:
If Delilvery Completed Indicator (0COMPL_DEL) = x, calculate No. of Line Items (ZPO_CNT) from 0CALDAY to 6 months
and
Number of completed line items in past 12 months:
If Delilvery Completed Indicator (0COMPL_DEL) = x, calculate No. of Line Items (ZPO_CNT) from 0CALDAY to 12 months
Please let me know if the logic is correct. If so, how I can create this in report
Maybe you are looking for
-
Translation of enumeration texts
I'm calling an RFC module, one of the parameters' type is a user-defined data element. Its value range is defined as Fixed value | Short text 1 | Text1 2 | Text2 3 | Text3 When I choose Goto->
-
Hi, i have a problem with a file:ExampleTag.java package coreservlets.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; public class ExampleTag extends TagSupport { public int doStartTag() { try { JspWriter out =
-
L_TO_CREATE_DN
Hi, in my code i have: SELECT * FROM lips INTO TABLE tlips WHERE vbeln = likp-vbeln. IF NOT tlips[] IS INITIAL. CLEAR: it_delit, l_wa_delit. REFRESH it_delit. LOOP AT tlips INTO wa_tlips. Compruebo el estatus de la posición
-
The Help Tab (OSX ML) where you search for something does not work
If I click "Help" and then search "expand" it will show me where expand is. But in CS6 when I clicked it the command would go through and pull up the page to expand pixels. Instead, I have to go find it. It works in every other Adobe app I use except
-
Can we change the controls in PCUI
Dear All, I am very new to pcui. I want to change the custom search in pcui screen. Let me expalin u: If we go to transaction and press F4 we will get the list of transaction but same thing I want to do in drop down box instead of list. Can I change