Count of rows having different values
SQL> select * from med;
CERT REC PRIM RACE
100 10 EN USA
100 11 EN USA
100 12 EN USA
100 13 SP MX
200 14 SP MX
200 15 SP MX
6 rows selected.
SQL> select * from sub;
CERT REC PRIM RACE
100 10 EN USA
100 11 EN USA
100 12 EN USA
100 13 SP MX
200 14 SP MX
200 15
6 rows selected.
SQL> select * from den;
CERT REC PRIM RACE
100 01 EN USA
100 02 EN USA
100 03 EN USA
100 04 SP MX
200 06 SP MX
(cert,rec) uniquly identifies a person;
In Den table rec =med.rec-9 or rec =sub.rec-9 which implies
med sub den
(cert,rec)=(100,10)=(100,10)=(100,01)How can I find out how many people in the table where the PRIM and RACE hold different values.?
Hi,
Perhaps this ,
with med as (
select 100 CERT, 10 rec, 'EN' prim, 'USA' race from dual union all
select 100 , 11, 'EN', 'USA' from dual union all
select 100 , 12, 'EN', 'USA' from dual union all
select 100 , 13, 'SP', 'MX' from dual union all
select 200 , 14, 'SP', 'MX' from dual union all
select 200 , 15, 'SP', 'MX' from dual )
sub as (
select 100 CERT, 10 rec , 'EN' prim, 'USA' race from dual union all
select 100, 11 , 'EN', 'USA' from dual union all
select 100, 12 , 'EN', 'USA' from dual union all
select 100, 13 , 'SP', 'MX' from dual union all
select 200, 14 , 'SP', 'MX' from dual union all
select 200, 15, null, null from dual )
den as (
select 100 cert, 01 rec, 'EN' prim, 'USA' race from dual union all
select 100, 02, 'EN' , 'USA'from dual union all
select 100, 03, 'EN' , 'USA'from dual union all
select 100, 04, 'SP' , 'MX'from dual union all
select 200, 06, 'SP' , 'MX'from dual )
----- sample data
select cert, prim, race ,count(rec) rec
from (
select *
from med
union all
select *
from sub
union all
select *
from den
group by cert, prim, race
ORDER BY 1,2,3
CERT PR RAC REC
100 EN USA 9
100 SP MX 3
200 SP MX 4
200 1HTH
SS
Similar Messages
-
Adding a parameter with comma separated having different values
i want to add a parameter with comma separated having different values of a column. e.g i have column having values from 10000 to 99999. i want to create report for the selected values of 11111,12111,131111 etc. This selection can be one or more values as desired. Second problem is restricting the records as per parameter.
Reports doesn't allow multi-selection of a parameter in its parameter form. You need to use Oracle*Forms or an HTML Form to front end more advanced parameter form options.
However, you could have multiple parameters and combine their selections into a single parameter in the after parameter form trigger. This would at least allow you to give the user the option for selecting up to 'n' parameters. The single parameter would have to be of type "character" and you probably want to add appropriate quotes around the values in the after parameter form trigger.
Second problem is restricting the records as per parameter. Once you've got the comma seperated values into a single parameter (say p_myValues with a default value of '') then you can just use a lexical parameter to restrict the values as in:
select * from emp
where to_char(empno) in (&p_myValues) -
Updating multiple rows with different values
Hi!
I have a problem. I need to update more then 1000 rows with different values. How can I do it?
For exsample i have table:
id; color, date,
1 red
2 green
3 white
I need to update date field.
Update table
set date='01.02.03'
where id=1
Update table
set date='01.03.03'
where id=2
Maybe there is way how to update multiple rows at one query?
Sorry for my bad english.
Thanks!Hi,
You can try this
UPDATE TABLE SET DATE = CASE
WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
ENDcheers
VT -
Update multiple row for different values
hi,
Please provide me the sql query to update multiple row in a table with different values.
i need to change the old date to new date
we have only 3 column id,name,old date.now i need to update the old date to new date
ID name old date new date
1 A 2012-12-20 12/7/2012
2 B 2012-12-20 12/9/2012
3 c 2012-12-20 12/5/2012
thank you.Here are two ways to do this. Thanks to ranit for the table creation script, which I adapted.create table test_x
as
select 1 id, 'A' name, to_date('2012-12-20','yyyy-mm-dd') old_date
from dual UNION ALL
select 2 id, 'B' name, to_date('2012-12-20','yyyy-mm-dd') old_date
from dual UNION ALL
SELECT 3 ID, 'C' NAME, TO_DATE('2012-12-20','yyyy-mm-dd') OLD_DATE
from dual;First method using MERGE:MERGE INTO TEST_X O
USING (
select 1 id, to_date('12/7/2012','mm/dd/yyyy') new_date
from dual UNION ALL
select 2 id, to_date('12/9/2012','mm/dd/yyyy') new_date
from dual UNION ALL
SELECT 3 ID, TO_DATE('12/5/2012','mm/dd/yyyy') NEW_DATE
FROM DUAL
) n
ON (O.ID = N.ID)
WHEN MATCHED THEN UPDATE SET OLD_DATE = n.NEW_DATE;Second method using UPDATE:UPDATE TEST_X SET OLD_DATE =
CASE WHEN ID = 1 THEN TO_DATE('12/7/2012','mm/dd/yyyy')
WHEN ID = 2 THEN TO_DATE('12/9/2012','mm/dd/yyyy')
WHEN ID = 3 THEN TO_DATE('12/5/2012','mm/dd/yyyy')
END
where id between 1 and 3;
You probably don't want to use these methods.*
You say the "user" will enter these values. Will he always enter exactly 3 values?
The "user" will enter values into a screen I suppose. What language is the user interface programmed in? -
Count of rows from different tables.
Hi Friends,
I have 4 tables with a common column name "ID". I would like to get the count of rows from all the four tables which has the same ID.
Ex
select count(a.id) from table1 a,table2 b,table3 c,table4 d where a.id=b.id=c.id=d.id=5;
please suggest me some solutionmay be thsi?
select count(a.id) from table1 a,table2 b,table3 c,table4 d
where a.id=b.id and a.id=c.id and a.id=d.id and a.id=5; -
Count MySQL rows based off Value in Dynamic Table
Greetings all. I have 2 MySQL tables; 1 that contains the names of my classes.(Class A, Class, B, etc.) and 1 table that contains the names of students in each Class (for example Class A: John Doe; Class A: Susie Smith.; Class B: Jane Doe). In the 2nd table the Class name is in its own column and the student's name is in a 2nd column.
I currently have a dynamic repeating table that lists the names of all of the classes from the 1st table. What I'm trying to do is add a second column to this repeating dynamic table that lists the number of students in each class. For example; Row 1 of the dynamic table would say "Class A | 5; Class B | 3; Class C | 7, etc.). The dynamic table works perfectly to list the class names. For the life of me I can't figure out how to perform a count for each class to insert in the repeating table. I will be adding more Classes which as why I'm trying to set up the counting query dynamically. So far I have only been able to figure out how to count the total rows in the 2nd table, or count the rows with a specified class name. Any advice or guidance on how to count the number of rows in the 2nd MySQL table based off the class name in the repeating table is much appreciated. Thank you for any and all help. Have a great day.Select count(*), Class from MyTable
Group by Class
Time to learn about SQL:
http://www.w3schools.com/sql/sql_intro.asp -
Count the rows which differes a column value
msg deleted
Edited by: user11253970 on Jul 14, 2009 11:33 AMPerhaps this
with a as (
SELECT cert_no, count(distinct RACE_CODE) RACE_CODES FROM subscriber
group by cert_no having count(distinct RACE_CODE) > 0 )
b as (
SELECT cert_no, count(distinct RACE_CODE) RACE_CODES FROM med_subscriber
group by cert_no having count(distinct RACE_CODE) > 0 )
c as (
select cert_no, count(distinct RACE_CODE) RACE_CODES from den_subscriber
group by cert_no having count(distinct RACE_CODE) > 0 )
select cert_no, a.race_codes + b.race_codes||' (in med_subscriber and subscriber tables)'
||' , '|| c.race_codes ||' (in den_subscriber table).' col1
from a , b , c
where a.cert_no = b.cert_no
and a.cert_no = c.cert_no
note: not tested for your data.
SS -
Finding fields having different values
Hi
There are two internal tables with same structures, each holding single record. However, the values of those records are different.
I need to find out the fields in which the values are different.
How can I perform this.
Could any one help?
Thanks
DivyaHello Divya
You could do a field-by-field comparison, e.g.:
" Read single record of each itab into work area
FIELD-SYMBOLS:
<ld_fld1> TYPE ANY,
<ld_fld2> TYPE ANY.
DO.
ASSIGN COMPONENT syst-index OF STRUCTURE ls_record1 TO <ld_fld1>.
ASSIGN COMPONENT syst-index OF STRUCTURE ls_record2 TO <ld_fld2>.
CHECK ( syst-subrc = 0 ). " assign worked
IF ( <ld_fld1> NE <ld_fld2 ).
ENDIF.
ENDDO.
Or you may use a more generic approach which will work for all records of itabs having the same structure. This approach gives you new, modified and deleted records: [Comparing Two Internal Tables - A Generic Approach|https://wiki.sdn.sap.com/wiki/display/Snippets/ComparingTwoInternalTables-AGeneric+Approach]
Regards
Uwe -
GR having different values for same quanitity
Hi All,
We have a Scheduling Agreement for which different GRs are posted through Inbound Delivery. The problem is, for two different GRs which were posted on the same day(for diifferent batches) having the same quanity, the GR values are different at decimal places. ie. 0.01 EUR difference.
Scheduling Agreement : Target Qty - 326,700.000ST ; 143.35 EUR per 1000ST
Quantiy
Amount
Goods Receipt 1
7425 ST
1064.37 EUR
Goods Receipt 2
7425 ST
1064.38 EUR
So, here, the actual amount should be 1064.37EUR (7425 x 0.14325 = 1064.37375) after roundong off to two decimal places.
Please suggest. Thanks in advance.
Regards,
RoshHi,
This will happen due to small difference of exchange rate even though there is not changes applied to exchange rate in system.
The un-expected exchange rate difference posted during GRN is very well explained in below KBA.
The KBA explains the real situation why this difference are caused and corresponding way to handle this type of situation.
KBA: 1686557 - Unexpected exchange rate difference during goods receipt
Rgds, -
How do I create a count of all the different values in a column
I'm using Numbers 09, and I have a table with over 20,000 rows. Each row is a record of a digital asset download. I'm trying to get a list how many times each asset was downloaded. For example, if my table looked like this:
Category
a
c
b
b
c
c
a
a
c
a
Then I want my second table to look like this.
Category
Count
a
4
b
2
c
4
I would like the function to automatically pull the categories out, because I have hundreds of them. Doing a countif would be an absolute pain.
Thanks.Zach,
It's not the programming that will be the greatest pain, it will be the slowness of a Numbers document with 20,000 rows.
Here's a small example which you can use on your large database if you wish...
Column B of table "Data" contains:
=IF(COUNTIF(OFFSET($A$1, 0,0, ROW()-1),A)=0, MAX(OFFSET($A$1, 0, 1, ROW()-1))+1, "")
Column A of table "Summary" contains:
=IF(MAX(Data :: B)>=ROW()-1, LOOKUP(ROW()-1, Data :: B, Data :: A), "")
and, column B of table "Summary" contains:
=COUNTIF(Data :: A, A)
Regards,
Jerry
...a tip on Filling the expressions to thousands of rows: Paste my expression into the first body row (Row 2) cell and click the Accept button. Commend-C to Copy the Cell. With the cell just below selected, scroll to the last row and Shift-Click the last cell in the column. Then Command-V to Paste to the entire rest of the column. Don't try to use the Fill Handle -- it will take forever that way.
Jerry -
Count of rows from different Columns
SELECT (SELECT COUNT (empno) empno
FROM emp) empno, (SELECT COUNT (mgr) mgr
FROM emp) mgr, (SELECT COUNT (sal) sal
FROM emp
WHERE sal > 2000) sal
FROM DUAL;Hi friends
Please let me know any better solutions for this query..??user10594152 wrote:
Please let me know any better solutions for this query..??Why not just..
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select count(empno) as emps
2 , count(mgr) as mgrs
3 , sum(case when sal > 2000 then 1 else 0 end) as sals
4* from emp
SQL> /
EMPS MGRS SALS
14 13 6
SQL> -
How to hide complete row having zero values
Hi All,
I have a requirement in my rtf template.
I have different amount fields in my rtf template.If my output contains all amount as zeros in a single row then i should skip this row.(that menas it should not display that complete row in my output.).
Could anyone please help me out.
Thanks in Advance,
DhanaHi,
You can create a variable named show_row which is set to yes if all your conditions returns true.
Then you make a check on your variable before the first column of your table and end it after the last column.
<?foreach...?><?if:show_row='yes'?>column1 column2 .... <?end if?><?end foreach?>
BR Kenneth -
Sortable jtable with jcombo having different values
Hi,
I have a contacts list with name, addrerss etc., and telephone numbers where each contact can have several telephone numbers.
The data is stored in a Derby DB in two tables with a PK and FK relationship. I need to load all the Contact fields in to a JTable where one of the columns will be the JCombos with telephone number(s) for that paticular contact.
I have studied two neat sample code segments posted by a senior mrmber "camickr" at;
[http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581 |http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581 ]
Also another by " skdaga " at;
[http://forums.sun.com/thread.jspa?threadID=749031&messageID=4284078|http://forums.sun.com/thread.jspa?threadID=749031&messageID=4284078]
both are solid working examples.
My problem is that I need to let the user to sort the table by columns and also filter by a text box entry. Meaning, the Combo boxes cannot have a fixed row index.
Could someone advice if this is possible or I should use some other approach.
Thanking you in advance,Hi camickr;
Many thanks for your kind reply. I have managed to slightly modify your code to load the combos of individual telephone numbers dynamically.
I have done so by returning a TableCellEditor from the public TableCellEditor getCellEditor(int row, int column) method, in place of storing the
DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 ); etc., in an ArrayList.
It goes as this. Following method is called by the return statement.
private TableCellEditor createCellEditorWithCombo(int contactId) {
JComboBox cmbNumbers = new JComboBox( <passed a Vector here thro' a PreparedStatement from the DB>);
DefaultCellEditor editor = new DefaultCellEditor(cmbNumbers);
return (TableCellEditor)editor;
}The contactId of course could be easily desiphered from the "row" parameter then and there.
I will follow your advice on the sorting part (on which I am yet to read the API fully) and get back with the result. Btw, I use the JDK 1.6u7 with Netbeans 6.1
Thanking you once again for your great contributions,
ViKARLL
NB: By the way;
camickr wrote:
Well, if you look at my example you will note it uses the convertColumnIndexToModel(...). So you need to do the same thing for the row.It looks like you are referring to a diffrent post by you, since your example I worked on does not contain this method ??
Edited by: ViKARLL on Sep 13, 2008 4:19 AM -
Count the rows in a list-component
Hi,
How can I count the rows with a value in a list component?
I thought it would be RowCount but as I figured out that shows the number of shown rows, not the number of rows with a value.Hi,
Try list.dataProvider.length -
Aperture shot is recorded at different values in output file
Dear Lens users,
Please explain why the aperture values which I used in my images for my sets that I used to profile my lenses, are showing up in the output data, in the .LCP file, as having different values. For instance, at f2.8 which I used for several lens image sets, the aperture value is listed as "2.970854" and not as 2.8. Likewise for my shot aperture of f8, the aperture value listed in the output .LCP file is 6.00000.
There must be some technical explanation of why the apertures shown on the aperture ring(when there is one) or camera screen, traditional apertures thought of as f2.8, f4, f5.6, etc., are stated within the data files as other values, close but not the same.
Thanks, DebraThank you phototrek and T.Phanngam.
I do not see the value "FNumber" in any of my profile .LCP Files, unfortunately, I only see only the ApertureValue(I also used "Search" for "FNumber").
T.Phanngam - thanks very much for the pdf file on the technical white paper on the Lens Profile Creator - I have not seen this document before. I am printing it to read it thoroughly.
Thanks to both for replies,
Debra
Maybe you are looking for
-
I have installed two virtual machines(win2k3 32bit and win2k3 64bit ) on Windows Server 2008 RC1 With Hyper-V Technologies (Beta) enterprise. Mouse is getting lost inside VM (using CTRL+ ATL + LEFT ARROW comes mouse control control in host OS). Is
-
ITunes won't install in Windows 8.1
I Clicked Download iTunes after selecting it for Windows 8, 64 bit. A new screen came up, thanking me for downloading iTunes, and describing all its features. That's great, but where is the download? I don't get an error message, I get nothing. What
-
Hi Friends, I have developed a abap program that download a excel file to a application server. i need to send the file to a shared folder or share point using FTP. How can i send the file which is in Application server thru FTP? Can anybody guide me
-
How do I get a calculation from an Interface?
Money calculateGrossPay(); is part of my interface, I have to calculate the grossPay and I can't convert between double and Money. Can you tell me how? I don't have the option of changing the rate to a double. I have to make it work like this. privat
-
Changing the Target data store dynamically
Hi, I have a requirement to load same kind of data into 12 different target tables. Client maintains data in period vise, i.e. Jan data in a table TABLE_01, Feb data in TABLE_02, Dec data in TABLE_12 etc. The structures of all these tables are same.