|
|||||||||||
|
Group wise maximum
From: Dave G <mysql(at)godseyfamily.com>
Date: Thu Jun 28 2007 - 15:07:10 EDT
I need the group-wise maximum of this query based on payload_time: CREATE PROCEDURE `getElement`(IN id INT UNSIGNED,
IN ptime DOUBLE,
IN tid VARCHAR(255),
IN exact_time TINYINT)
BEGIN
IF(ptime < 1) THEN SELECT MAX(ROUND(payload_time,6)) FROM data__ProcessedDataFrames WHERE test_id=tid INTO ptime; END IF;
J.product_id,
P.processed_id,
MAX(ROUND(P.payload_time,6)) as payload_time,
P.top_level_product_name,
SUBSTR(
BINARY(processed_data),
FLOOR(J.product_offset/8)+1,
CEIL(J.product_length/8)) as substring,
(SELECT HEX(substring)) as raw_data,
(SELECT toString(
substring,
round(char_length(raw_data)/2,0),
data_type,
(SELECT attribute_value FROM
config__DataProductAttributes
WHERE attribute_name='FormatString'
AND config__DataProductAttributes.product_id=
J.product_id),
product_offset % 8,
(product_length+(product_offset % 8)) % 8,
product_length,
byte_order,
(SELECT attribute_value FROM
config__DataProductAttributes
WHERE attribute_name = 'ConvParams'
AND config__DataProductAttributes.product_id =
J.product_id))) as converted_data,
(SELECT enum_name FROM
config__DataProductEnumConversions
WHERE product_id=J.product_id
AND enum_value =converted_data) as enumerated_data,
(SELECT metricTest(converted_data,
(SELECT xmlTestMetric FROM
test__TestMetrics
WHERE product_id = J.product_id))) as test_metric
FROM data__ProcessedDataFrames
P INNER JOIN
(SELECT E.product_id,
top_level_product_name,
product_length,
product_offset,
data_type,
byte_order
FROM display__DataProducts_in_Element
E INNER JOIN config__DataProducts D ON
E.product_id=D.product_id
WHERE E.element_id=id) J
ON P.top_level_product_name=J.top_level_product_name
WHERE P.test_id=tid
AND payload_time <= ptime
GROUP BY J.product_id ;
END;;
mysql> desc data__ProcessedDataFrames;
+------------------------+------------------+------+-----+---------+----------------+6 rows in set (0.00 sec) mysql> This table can get quite large so I'm trying not to query on it twice to get the MAX(payload_time) < ptime. Obviously what I have is not the group-wise maximum I was hoping for. Dave G. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=lists@pantek.comReceived on Thu Jun 28 15:08:14 2007 This archive was generated by hypermail 2.1.8 : Thu Jun 28 2007 - 15:10:03 EDT |
||||||||||
|
|||||||||||