To find max effdt from a table
i am facing problem in finding max effdt for every employee from a table.
i have to fetch emplid's from a table according to a particular deptid but there are many entries for a employee depending on effdt.I have to fetch the entry which is of max effdt.
i wrote query like dis,is it ok?
select emplid,effdt from ps_job where deptid='10000' and effdt in (select max(effdt) from ps_job group by emplid)
You need to correlate the effdt and the empid is some fashion There are a few ways to do this. The closest correct way to what you have is:
SELECT emplid, effdt
FROM ps_job o
WHERE deptid='10000' and
effdt IN (SELECT MAX(effdt) FROM ps_job i
WHERE i.emplid = o.emplid)A one-pass method, assuming you can use analytics would be:
SELECT emplid, effdt
FROM (SELECT emplid, effdt, deptid,
ROW_NUMBER() OVER(PARTITION BY emplid
ORDER BY effdt DESC) rn
FROM ps_job o)
WHERE deptid='10000' and
rn = 1John
Similar Messages
-
How to find max(time) from table using group by
how to find max(time) from table using group by
select var max(time)
from table
into (var1, time1)
where .....
group by var.
it is fetching record which is top in table.
if u can help?
regards.No this will fetch the maximum time from teh table.
select var max(time)
from table xxxx
into (var1, time1)
where .....
group by var.
Refer this code
TABLES SBOOK.
DATA: COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
DATA: CONNID LIKE SBOOK-CONNID.
SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
INTO (CONNID, COUNT, SUM, AVG)
FROM SBOOK
WHERE
CARRID = 'LH ' AND
FLDATE = '19950228'
GROUP BY CONNID.
WRITE: / CONNID, COUNT, SUM, AVG.
ENDSELECT. -
Select max date from a table with multiple records
I need help writing an SQL to select max date from a table with multiple records.
Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
0000651005 BASE 15-AUG-07 YES
0000651005 BASE 13-NOV-09 NO
0010973671 BASE 20-MAR-08 YES
0010973671 BASE 18-JUN-10 NOHi,
Welcome to the forum!
Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
For example:
CREATE TABLE table_x
( sa_id NUMBER (10)
, char_type VARCHAR2 (10)
, effdt DATE
, char_val VARCHAR2 (10)
INSERT INTO table_x (sa_id, char_type, effdt, char_val)
VALUES (0000651005, 'BASE', TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
INSERT INTO table_x (sa_id, char_type, effdt, char_val)
VALUES (0000651005, 'BASE', TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
INSERT INTO table_x (sa_id, char_type, effdt, char_val)
VALUES (0010973671, 'BASE', TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
INSERT INTO table_x (sa_id, char_type, effdt, char_val)
VALUES (0010973671, 'BASE', TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
` SA_ID LAST_EFFD
651005 13-NOV-09
10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
Here's how to get those results:
SELECT sa_id
, MAX (effdt) AS last_effdt
FROM table_x
GROUP BY sa_id
; -
Selecting a MAX value from a table & displaying it on a form using OCI PHP
WinXP Pro SP3- 32bit
Apache/2.2.22 (Win32) mod_fcgid/2.3.6 PHP/5.4.0
PHP Version 5.4.0
Oracle epxress 11g
problem: output on form displaying Resource id #4 instead of the number from the table.
(maybe it's number to string conversion issue?)
$conn = oci_connect('system', 'mypassword', 'localhost/xe');
$query = "SELECT MAX(CustNo)+1 AS MAXNUM FROM customer";
$stmt = OCIParse($conn, $query);
OCIExecute($stmt);
OCIFetch($stmt);
echo OCIResult($stmt, "MAXNUM")." will be next number.";
//OCIFreeStatement($stmt); //frees the resources- use a the end!
$daNextNo = $stmt;
echo $daNextNo;
//$daNextNo = OCIBindByName($stmt, ":text", &$form_text, -1); //not sure how this works if it'll fix the issue
?>
<form name="Addcust" action="process_cust.php" method="post">
<input type="text" name="CustNo" value="<?php echo $daNextNo;?>" /></br>
output of complete code:
45 will be next number.Resource id #4
And inside the textbox it says: 45 will be next number.Resource id #4
how can I put the 45 into $php variable so i can use it in a textbox or on a label?
Thank you in advance .THanks. i couldn;t find the PHP section.
I figured it out
i used nextval() to convert the object to a string.
<?php
$conn = oci_connect('system', '1234', 'localhost/xe');
if (!$conn) {
$m = oci_error();
trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
$query = "SELECT MAX(CustNo)+1 AS MAXNUM FROM customer";
//$daNextNo = $query;
$stmt = OCIParse($conn, $query);
OCIExecute($stmt);
OCIFetch($stmt);
echo OCIResult($stmt, "MAXNUM")." will be next number.";
//OCIFreeStatement($stmt); //frees the resources- use a the end!
$daNextNo = strval(OCIResult($stmt, "MAXNUM")." .");
$daNextNo = strval(OCIResult($stmt, "MAXNUM"));
echo "danextNo: ";
echo $daNextNo;
?>
<form name="Addcust" action="process_cust.php" method="post">
<div>
<dl>
<dt>* <?php //echo $this->lang->line('cust_fn'); ?>: </dt>
<dd><input type="text" name="CustNo" value="<?php echo $daNextNo;?>" /></dd> -
Min and Max values from entire table
Hi,
i have requirement in which i need to find the min and max values from the entire table.
See the sample data
create table test
Sal1 int,
Sal2 int,
Sal3 int
insert into test values (100,700,5700)
insert into test values (200,3300,5300)
insert into test values (4400,1200,3500)
insert into test values (5400,5600,3100)
i want the output as 100 and 5700.. how can i achieve this in a single query. Please through some light on this topic..!
Thanking you in advance
Regards,
Balaji Prasad B
Balaji - BI DeveloperBelow is an example with a subquery for each of the queries Mohammad posted in order to return both min and max in a single result set.
SELECT ( SELECT MAX(Maxx) AS Maxx
FROM test UNPIVOT
( Maxx FOR E IN ( Sal1, Sal2, Sal3 ) ) AS unpvt
) AS Maxx
, ( SELECT MIN(Minn) Minn
FROM test UNPIVOT
( Minn FOR E IN ( Sal1, Sal2, Sal3 ) ) AS unpvt
) AS Minxx;
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
How to Find out the from which table we can get the following fields?
The following fields are from invoice data
How to know or from which table we get the following fields:
Header Details:
Manifest:, Finance Control #:, Alternate SID:, Carrier:, Container/Trailer #:, Hazmat Code:, Harmonizing Code, Freight Forwarder, Fiscal Rep., Ship From, Notify Party
Item Details:
VAT/Tax Rate %, VAT/Tax Amount, Measurements, Net Weight, Gross Weight
thanksDear Krishnama
Place your mouse on the required fields and press F1. A box with header Performance Assistant will appear in front of you where you select "Technical information" (icon like hammer and spanner).
You can now see what table it is.
thanks
G. Lakshmipathi -
How to find max value from a list of numbers stored in a varray?
hi,
Can any body help me to get the max value from a list of numbers stored in a varray?
thanks in advance....
regards
LaxmiNarsimhaYes. Could you post what you have tried before we start helping you in this?
-
How to find worksheet name from EUL5* tables.
Hi
I created workbook called employee report.
under that 3 worksheets created.
worksheet1 - By EMPNO
worksheet2 - By DEPTNO
worksheet3 - By JOB.
how can i find the worksheet name from the EUL5* tables?Hi Marias,
To find the worksheets run the below query
select distinct qs_doc_name WBOOK_NAME,qs_doc_details WSHEET_NAME
from eul5_qpp_stats where qs_doc_name in(select doc_name from EUL5_documents)
Regards
Sridhar -
Finding the fields from the table.
in which table i will find
brand ( ex : raymonds, park avenue like)
color ( ex : red,green, yellow;.........etc)
style...( ex : long,short, medium)
these fields are required for generating the sales order report daily........
what r the tables req for this report......
thanks & regards,
kartik p.Hi,
Some SAP standard fields may have been used to save this information. Since they are product related, I am suspecting any of the following fields may have been used.
1. Material group (VBRP-MATKL)
2. External material group (not found in invoice directly; to be retrieved from MARA based on material code - MATNR. Field EXTWG)
3. Any of the 5 material groups - Material groups 1 - 5 (VBRP-MVGR1, VBRP-MVGR2, VBRP-MVGR3, VBRP-MVGR4, VBRP-MVGR5).
If this data is required for 'order report', then VBRP given above can be replaced with VBAP.
Cheers,
KC
SAP SD
Edited by: Krishna Chandika on May 9, 2008 7:16 PM -
Find missing data from parent table
hI,
PLEASE IGNORE ABOVE STATEMENT JUST NOW GOT THE RESULTS
SELECT c.table_name CHILD_TABLE, p.table_name PARENT_TABLE
FROM user_constraints p, user_constraints c
WHERE (p.constraint_type = 'P' OR p.constraint_type = 'U')
AND c.constraint_type = 'R'
AND p.constraint_name = c.r_constraint_name
AND c.table_name = UPPER('ODS_TSAF_MES_PC');
and output is
child table parent table
ODS_TSAF_MES_PC
ODS_TSAF_MES_PCTYP
ODS_TSAF_MES_PC
ODS_TSAF_MES_PC
ODS_TSAF_MES_PC
ODS_TSAF_MES_PCSTAT
i tried
SELECT A.piecestatus from ods_TSAF_MES_PCSTAT A
WHERE NOT EXISTS
(SELECT * FROM ODS_TSAF_MES_PC B WHERE B.piecestatus = A.piecestatus);
and i found one piecestatus values is 'I' but i am not getting where it is related to the table and in which row it is getting affected?
want to know which row is getting affected
thankssorry
hI,
I have executed the query to find parent child relationship and got the results
SELECT c.table_name CHILD_TABLE, p.table_name PARENT_TABLE
FROM user_constraints p, user_constraints c
WHERE (p.constraint_type = 'P' OR p.constraint_type = 'U')
AND c.constraint_type = 'R'
AND p.constraint_name = c.r_constraint_name
AND c.table_name = UPPER('ODS_TSAF_MES_PC');
and output is
child table parent table
ODS_TSAF_MES_PC
ODS_TSAF_MES_PCTYP
ODS_TSAF_MES_PC
ODS_TSAF_MES_PC
ODS_TSAF_MES_PC
ODS_TSAF_MES_PCSTAT
now i wanted to find which exactly row is missing in parent or child table so i executed below mentioned query
SELECT A.piecestatus from ods_TSAF_MES_PCSTAT A
WHERE NOT EXISTS
(SELECT * FROM ODS_TSAF_MES_PC B WHERE B.piecestatus = A.piecestatus);
and i found one piecestatus values is 'I' but i am not getting where it is related to the table and in which row it is getting affected?
want to know which row is getting affected
thanks -
How to find common columns from two tables
regards
812809 wrote:
regardsHi,
Use User_tab_cols view to extract the result.
Try
SQL> create table test3(id number(10),name varchar2(10));
Table created.
SQL> create table test4(id number(20),addr varchar2(200));
Table created.Now query user_tab_cols
SQL> select column_name from user_tab_cols where table_name='TEST3'
2 intersect
3 select column_name from user_tab_cols where table_name='TEST4'
4 /
COLUMN_NAME
IDHope this helps
Regards,
Achyut
Ps-> Mark as Complete/Answered if it meets your requirement -
I have two tables - table1 and table2 - that have the exact same schema. There are three fields that can be used to compare the data of the two tables, field1, field2, and field3. When there are matching rows in the two tables (table1.field1/2/3 = table2.field1/2/3)
I want to replace table1.field4 with table2.field4 and replace table1.field5 with table2.field5.
I have worked with the query but have come up with goobly goop. I would appreciate any help. Thanks.If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ; -
Can't Find Owning Entity From Detail Table With 2 Masters
Hi,
I've got a master detail table relationship working with association and view link but when I try to do it again with the same detail table but a new master table I am getting the error, JBO-25030: Detail entity RulBAAG with row key oracle.jbo.Key[null 6A ] cannot find or invalidate its owning entity.
I really don't want to have to create a seperate set of EOs and VOs for this second relationship. Is there something I can do programaticaly to identify which master / detail relationship the CRUD operation is for? Thanks-
Master1 table: PK and FK, BId
Master2 table: PK and FK, AgId
Detail table: PK, BId & AgIdGabz,
I believe you need to create the database foreign key relationship with "cascade on delete" set. Then ensure that your association in BC4J that models this relationship also has the "cascade on delete" property set (it should by default).
With this set, deleting the master should automatically delete the children.
Hope this helps,
-brian
UIX Team -
Selecting Max Value from Huge Table
Dear Proffessionals
I have a huge table (20,000,000+ records) with the following columns:
[Time], [User], [Value]
The values in [Value] column can recur for a single User at a Time e.g.
2015-01-01, Me, X
2015-01-01, Me, Y
2015-01-01, Me, X
2015-01-02, Me, Z
2015-01-02, Me, X
2015-01-02, Me, Z
For each day, and for every user I want to have the maximum recurring value :
2015-01-01, Me, X
2015-01-02, Me, Z
to be inserted into another table.
PS: I want the MOST optimized way of achieving this functionality, bcause I am expecting a growth on the raw table over time, so PERFORMANCE is of great consideration.
I would really appreciate it, if somebody can help me.
RegardsI can think of two techniques based on the data selecticity
1) using row number function
2) using cross apply operator
USE Northwind;
-- Solution 1
SELECT S.SupplierID, S.CompanyName, CA.ProductID, CA.UnitPrice
FROM dbo.Suppliers AS S
CROSS APPLY
(SELECT TOP (10) *
FROM dbo.Products AS P
WHERE P.SupplierID = S.SupplierID
ORDER BY UnitPrice DESC, ProductID DESC) AS CA
ORDER BY S.SupplierID, CA.UnitPrice DESC, CA.ProductID DESC;
-- Solution 2
WITH C AS
SELECT S.SupplierID, S.CompanyName, P.ProductID, P.UnitPrice,
ROW_NUMBER() OVER(
PARTITION BY P.SupplierID
ORDER BY P.UnitPrice DESC, P.ProductID DESC) AS RowNum
FROM dbo.Suppliers AS S
JOIN dbo.Products AS P
ON P.SupplierID = S.SupplierID
SELECT SupplierID, CompanyName, ProductID, UnitPrice
FROM C
WHERE RowNum <= 10
ORDER BY SupplierID, ProductID DESC, UnitPrice DESC;
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 -
How to find following data, from which tables
Hi all,
I want to display following fields in alv:
total stock of a werks KG
total stock of a werks EUR
company total rated stock KG
company total rated stock EUR
MG blocked stock KG
MG blocked stock EUR
Purchase orders whose confirmation type is FG KG
Purchase orders whose confirmation type is FG EUR
All purchase orders whether it has confirmation type or does not have KG
All purchase orders whether it has confirmation type or does not have EUR
Thanks.
deniz.hi,
check these standard transactions.
they may provide the data u required.
EW82 MM Stock Value List
AMRP Send Stock/Requirements List
LS26 Warehouse stocks per material
LX02 Stock list
MB5B Stocks for Posting Date
MB5K Stock Consistency Check
MB5L List of Stock Values: Balances
MB5L List of Stock Values: BalancesMB5W List of Stock Values
MC.1 INVCO: Plant Anal. Selection: Stock
MC.5 INVCO: SLoc Anal. Selection, Stock
MC.9 INVCO: Material Anal.Selection,Stock
MC50 INVCO: Analysis of Dead Stock
MMBE Stock Overview
OMBX Stock Balance Display
OPPI Available Stock
Maybe you are looking for
-
Error Installing SAP R/3 4.7 SR1 in AIX 6.1 with DB2 9.5
Hello, AIX 6.1 SP5, SAP R/3 4.7 SR1, DB2 9.5. I'm trying to install SAP R/3 4.7 SR1 and appears the error below during check / Adapt File System: TRACE [iaxxbnodes.cpp:1083] CIaOsNodes::checkTheFreespace() Need 80000 KB on mountpoint
-
Multimapping Problem - PI 7.0
Hi, To interface with a web service created in a BMC Remedy platfrom I need to create a Soap Envelope as detailed below: <soapenv: envelopeu2026.> <soapenv: header> <urn:AuthenticationInfo> <user nameu2026> <passwordu2026>
-
Test Equipment for Power Supply
Hi , I want to develop a test software for power supply using LabVIEW which we can use for our mass production. We are currently using the following for the development stage. 1. Digital Multimeter(Topward 1330) 2.Oscilloscope(Agilent DSO 6054A) 3.Pr
-
Why can't I install virtual devices in NI-Max with windows 7 and DAQmx 8.7.1
Hi all! I just got some new machines running Windows7 32 bit. The old ones didn't survive a fire, the DAQ devices were resqued. After I installed DAQmx 8.7.1 including NI-MAX I found out that my device (PCI-6014) wasn't displayed in the device sectio
-
Destination u have specified does not have read/ write access- FCP 7 to Compressor problem!
Hello everyone, I finally got a video finished in FCP 7, and sent it to Compressor. When I try to add a templete (any template, but particularly the Youtube), I get a red || Source ! || message and when I hit the submit button I see: "The destinat