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 Developer
Below 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
Similar Messages
-
Calculating min and max value from number array
I have array which is having return type Number.i want to calculate min and max value of this array..try to help asap..
Thanks
dhanuhi there,
public class MinMax {
int arr[]= { 27, 3, 42, 18, 243, -43, 6, -8 };
int min, max;
public MinMax() {
// it's very bad way to do it.
// min=99999;
// max=-99999;
// this must be as following
min = max = arr[0];
search();
System.out.println("The minimum value is: "+min);
System.out.println("The maximum value is: "+max);
private void search() {
// and here we can search from <1> index instead of <0>
for (int j=1; j<arr.length; j++) {
if (arr[j]<min) {
min=arr[j];
else if (arr[j]>max) {
max=arr[j];
public static void main(String args[]) {
new MinMax();
there is a bug in the supplied code. Your homework is
to figure out what it is without posting another
message for help with your homework.well, i think it's a tragedy :( -
Min and MAx Value in a SELECT Statement
Hi,
I have a scenario where I am Selecting the values BETWEEN MIN and MAX values:
SELECT * FROM ABC WHERE CODE BETWEEN MIN(CODE) AND MAX(CODE)
ITS GETTING Error as:ORA-00934: group function is not allowed here
Any help will be needful for me.select substr(no,1,3)||to_char(substr(no,4,1)+1) "first missing number"
from
with t as
(select 'ABC1' no from dual
union select 'ABC2' from dual
union select 'ABC3' from dual
union select 'ABC5' from dual
union select 'ABC6' from dual
union select 'ABC8' from dual
select no, lead(no,1,0) over (order by no) next_no from t
where substr(next_no,4,1) - substr(no,4,1) > 1
and rownum = 1; -
Highlighting Min and Max Values on each line
Hello,
Is it possible to highlight the Min and Max values on each row of a Query. For example I have sales below by product line for the last seven quarters. The user
would like the Max value (150) for Product Line ABC Highlighted as Green and the Min value (1055) color coded as Red. Like wise for each line - DEF 200 as green and 100 as red and GHI - 400 as green and 100 as red.
FYQ Q207 Q307 Q407 Q108 Q208 Q308 Q408
ABC 1500 1200 1400 1050 1100 1100 1100
DEF 1550 1000 1560 1220 1340 1640 2000
GHI 1000 2000 3000 4000 3250 2220 3750
Is this possible using Exceptions? or may be any other means? We are on Bex 7.0
Best Regards,
SanjivHello Sanjiv,
I think it can be done by JavaScript, but needs more effort
[Use of JavaScript Functions|http://help.sap.com/saphelp_nw04/helpdata/en/d9/4a853bc623c075e10000000a114084/content.htm]
Try the exception available in the BW[BW Stylesheets|http://help.sap.com/saphelp_nw04/helpdata/en/3f/ca453afbf37b54e10000000a11402f/content.htm]
SAPBEXformats - Formatting cell (scaling factors)
SAPBEXexcGood1 - Exception with priority good 1
SAPBEXexcGood2 - Exception with priority good 2
SAPBEXexcGood3 - Exception with priority good 3
SAPBEXexcCritical4 - Exception with priority critical 4
SAPBEXexcCritical5 - Exception with priority critical 5
SAPBEXexcCritical6 - Exception with priority critical 6
SAPBEXexcBad7 - Exception with priority bad 7
SAPBEXexcBad8 - Exception with priority bad 8
SAPBEXexcBad9 - Exception with priority bad 9
See this thread,
Change the colour of a cell text depending on the value Web Reports (NW04s)
Thanks
Chandran
Edited by: Chandran Ganesan on Mar 19, 2008 4:27 PM -
Quality parameter -min and max values should be maintained w.r.to contract?
Hi all,
Min and max values in quantity contract should be maintained with respect to contract. till now we were maintaing min and max values with respect to inspection plans, but here since it differs for customer/vendor contracts - it need to be with respect to that. kindly suggest me on this
regards,
SoumyaIn the Material Assignment TAB of the Inspection Plan Header, you can maintain or assign Vendor/Customer. These specifications will be assigned automatically for the Purchase Orders/Sales Orders for the Material/Vendor or Material /Customer Combination at Plant Level.
Check this and revert back.
Best Regards,
Raghavendra Nayak -
Read the min and max occurrence from XSD
Hi,
I have a scenario where I have an XML, but not its XSD so my question is of two fold
1. Is it possible to create an XSD from that XML, if possible how?
2. Assume I get the XSD how do I read the min and max occurrence from that XSD?
PS: I am coding in java and pretty new to it, so it would be really helpful if I get the code snippets for the same :)
Edited by: Harsha.Hegde on Sep 2, 2008 5:49 AMHarsha.Hegde wrote:
Hi,
I have a scenario where I have an XML, but not its XSD so my question is of two fold
1. Is it possible to create an XSD from that XML, yes
if possible how?by using a text editor, tools, etc.
2. Assume I get the XSD how do I read the min and max occurrence from that XSD?sigh
PS: I am coding in java and pretty new to itthen you should take some time to learn the basics, then work your way into XML after you have a grasp on things conceptually.
so it would be really helpful if I get the code snippets for the same :)sorry, no handouts here
do your own work
come back when you're written some Java and have a technical question -
Medium, min, and max values on ALV
Hi friends ! How are are you ? Fine ?
How can i calc medium, min, and max values on ALV ?
Thanks !Hi Fabrício
I think you set fieldcatalog at runtime dynamically to arrange dynamic columns. So, while you are setting it just set proper values to the attribute "do_sum" for relevant fields.
For more information how to set fieldcatalog dynamically, you can refer to the tutorial "An Easy Reference for ALV Grid Control".
Regards
*--Serdar [[ BC ] | https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk sag jiw=] -
OBIEE- Calculating Min and Max Values
Hi Friends,
I have an Issue with regards to calculating Min/Max Values.
In my Data base we dont have Message Count. So we created a Logical column in BMM Layer called "Message Count" based on the column "Out/In No" i.e by creating count of it i.e (Count(out/in no)) in BMM
To calculate Inbound Messages we writing -- filter(Message count using messagetype ='i') at report level
To calculate Outbound Messages we writing -- filter(Message count using messagetype ='o') at report Level
To calculate Total Messages we writing----- "Message Count".
But Now we had an issue to calculate "Min Inbound/Max Inbound/Min Outbound/Max Outbound/Avg In/Avg Out" types of Messages.
To make it clear definition for MIN and MAx is Like This.
Say Ravi received(Inbound) messages 2
Say Roy received(Inbound) messages 5
Say Kiran received(Inbound) messages 11 on a particular date.
So for that particular date Min Inbound is 2
So for that particular date Max Inbound is 11
and Avg Inbound will be (2+5+11)/3
On this basis we have to implement it in OBIEE. For any more clarifications please reply to my thread.
Please reply to my Issue ASAP as it is critical and I am out of time.
Thanks in Advance.
RegardsHi,
Do you mean to ask minimum stock in a plant and maximum stock in a plant over a period of time?
Due to receipts stocks flows in to the storage location of a plant. May be in one period there will be less stock or in one period there will be maximum stock.
May be history tables like MBEWH or MARDH or the report MC.9 ( you need to provide the period as input) etc for your case.If this is not your requirement please reply back.
Regards -
How to make validation in Bean and select value from another table
I want to know how to select data from table in backing bean according to primary key i have
the problem is that
i have a table Employee_Salary contains Employee ids and their salary
Empoloyee_Salary table
Employee_ID Number
Employee_salary Number
And Another table Called Employees
Employees table
Employee_ID Number
IsManager Varchar2 its value is [*Yes or NO*]
and other columns that i don't care about this table
i have on a jsff page an <af:table> this table is editable this is the Empoloyee_Salary table
*i want to check before save or after insert if this employee is Manager [from Employees tabke(yes or no)] the salary*
cannot be less that 100
i want to know how to make this how to select the value from employees table according to the id i have in the employee_salary table how to make this and make this validation
i have to select IsManager from Employees Table to see if this manager or no
i want to know how to make this in a bean
i use jdeveloper 11g
and my project is ADF Fusion project
and the page that have the Emplpyee_Salary table is JSFF
thanks in advanceYou might want to write this code in a validator on the entity object if it should apply from every screen.
If you want to access view objects from a backing bean the basics are here: http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918 -
How to show Min and Max values when another value "changes to a new value"
Hi
If I have this data (generated with this query: SELECT 1 A, 1 B UNION ALL SELECT 2, 1 UNION ALL SELECT 3, 2 UNION ALL SELECT 4, 2 UNION ALL SELECT 5, 1)
A B
1 1
2 1
3 2
4 2
5 1
How can I generate this data (created with this query SELECT 1 Amin, 2 Amax, 1 B UNION ALL SELECT 3, 4, 2 UNION ALL SELECT 5, 5, 1)
Amin Amax B
1 2 1
3 4 2
5 5 1
Thanks.Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. You also do not know the ANSI/ISO syntax for insertion and you did the old Sybase insertion kludge wrong, that we need keys, etc.
CREATE TABLE Foobar
(foo_seq INTEGER NOT NULL PRIMARY KEY,
glop_score INTEGER NOT NULL);
INSERT INTO Foobar
VALUE
(1,1),
(2,1),
(3,2),
(4,2),
(5,1);
>> How can I generate this data (created with this query SELECT 1 Amin, 2 Amax, 1 B UNION ALL SELECT 3, 4, 2 UNION ALL SELECT 5, 5, 1) <<
This makes no sense; you have the wrong syntax and mixed data types. My guess is:
SELECT MIN(foo_seg), MAX(foo_seq), MAX(glop_score)
FROM Foobar
GROUP BY glop_score
HAVING MIN(glop_score) = MAX(glop_score);
Amin Amax B
1 2 1
3 4 2
5 5 1
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
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> -
Hi All,
Query 1:I am trying to export the Chart data(Total plots 6 ) only between the X scale Min Time and Max time limit .
But couldnt able to achieve that progammtically.
is their anyway to achieve this.
Query 2:Also ,In chart their is an right click option to export data to excel,but when using this option the data get exported in its own temporary name(iv*****.tmp),i dont want this to happen.Instead the data expored using that option should be written in a file specified by me(everyting should happen in backend)
pls suggest the best solution for above 2 queries.
Thanks,
Selvan.Hi selvan,
1) read the chart history (or better keep a history in your own shift register) and limit the data to the XMin and XMax values (read all those chart settings from its properties). Then save the data using WriteToSpreadsheetFile…
2) The right-click option is as it is. When you need different behaviour you need to program your own routine. Once you finished query 1 it will be no problem anymore to also solve query 2…
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Get old and new values from DBTABLOG table
Hi,
I am developing a report to display all changes to some fields of PKHD table over a date range. CDHDR & CDPOS do not capture the changes while DBTABLOG does. But the variable key field (LOGDATA) in DBTABLOG does hold encrypted values which need to be decrypted. Is there any FM or a way out to get them ?
Please let me know. Thanks a lot.
Regards
NeerajUse DBLOG_READ and then work with the data like in the following sample
* Constants (cf. SAP RSVTPTOP)
CONSTANTS: type_i4 LIKE x031l-fieldtype VALUE 'AC', "UF160698B
type_i2 LIKE x031l-fieldtype VALUE 'A8',
type_f LIKE x031l-fieldtype VALUE '88'. "UF160698E
* First - informations from directory
REFRESH fld_list.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
langu = sy-langu
only = ' '
tabname = 'TEVEN'
withtext = 'X'
* IMPORTING
* HEADER =
* RC =
TABLES
fieldtab = fld_list
EXCEPTIONS
internal_error = 1
no_texts_found = 2
table_has_no_fields = 3
table_not_activ = 4
OTHERS = 5.
LOOP AT fld_list INTO fld WHERE keyflag = 'X'.
ADD fld-intlen TO keylen.
ENDLOOP.
* Then extract data log
REFRESH obj_list.
obj-tab = 'TEVEN'.
INSERT obj INTO TABLE obj_list.
CALL FUNCTION 'DBLOG_READ'
EXPORTING
from_day = s-aedtm-low
* FROM_TIME = '000000'
to_day = s-aedtm-high
* TO_TIME = '235959'
obj_list = obj_list
* ACCESS_DATABASE = 'X'
* ACCESS_ARCHIVES = ' '
* AUTO_ARCH_SEL = ' '
* USER_LIST =
CHANGING
log_list = log_list
EXCEPTIONS
archive_access_error = 1
no_archives_found = 2
OTHERS = 3.
* Extract data from returned tables
LOOP AT log_list INTO log.
LOOP AT fld_list INTO fld.
IF fld-keyflag = 'X'.
ASSIGN log-logkey+fld-offset(fld-intlen)
TO <hexa> TYPE 'X'.
ELSE.
fld-offset = fld-offset - keylen.
ASSIGN log-logdata+fld-offset(fld-intlen)
TO <hexa> TYPE 'X'.
fld-offset = fld-offset + keylen.
ENDIF.
CASE fld-inttype.
WHEN 's'.
f_type = type_i2.
WHEN 'I'.
f_type = type_i4.
WHEN 'F'.
f_type = type_f.
ENDCASE.
IF 'sIF' CS fld-inttype.
feld = <hexa>.
CALL FUNCTION 'DB_CONVERT_FIELD_TO_HOST'
EXPORTING
type = f_type
CHANGING
field = feld
EXCEPTIONS
wrong_param = 1
OTHERS = 2.
ASSIGN feld TO <hexa> TYPE 'X'.
ENDIF.
ASSIGN <hexa> TO <char> TYPE 'C'.
teven+fld-offset(fld-intlen) = <char>.
ENDLOOP.
* Here structure teven is filled
ENDLOOP.
Regards -
Single result recording valuation based on min and max values
hi,
Our client requirement is as follows:
While entering the single results recording the system should not calculate the average , we need the system should valuate based on the Minimum and Maximum values in result entry. Is it possible?. can anyone explain in details.
Regards,
Ramu.Hi
This is a standard SAP functionality available in SAP
As
Variable Inspection by S-Method
If you set this indicator, you define the valuation mode for the variable inspection according to the s-method (ISO 3951).
For a sampling procedure with this valuation mode, valuation occurs using a sampling plan consisting of sample size and k-factor. A quality score is calculated from the measured values of a sample and compared with the k-factor.
Now you want Both limits should come into picture while valuating then Check valuation Rule :31 -Variable insp. s-Method (two limits)
so select the Valuation mode : 310- Variable insp. s-Method (two limits) in sampling procedure.
I hope this will add some value.
Regars
Sujit -
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
Maybe you are looking for
-
App store does not open with 3gs iphone and new iOS6
download the new software yesterday it works great put on my phone the app store or itunes does not want to open can any body help???
-
SIDE QUESTION: Would having a thousand bookmarks affect firefox performance? Would an addon prevent the reset button from appearing? (tried disabling(the blocking, not the addon) the most likely culprit, adblock edge, nothing) safe mode seems to "dis
-
Web service task: Cannot see the expected list of methods
Problem in using web service task in SSIS I added web service in web service task but it wont retrieves me expected method in input. Can anyone please help me ASAP
-
Importing .exe files to dreamweaver
OK im going to make this as clear as i possibly can to stop confusing. i am making a site that will have a games section and i want people that come onto that site to be able to play those games on MY site. i do not know at all how to even get it ont
-
Burn DVD using Windows DVD Creator
I'm using Premiere Pro CC 2014 in a Windows 7 environment. DVD authoring is very much an exception for me but I find I need to do so on a project I finished last night. The Help files are full of needing Encore (which is no longer developed) to hand