always get a "not a GROUP BY expression" exception - sql

The select part is fine, I can run it and get result, but if I insert the query result into a table, the "not a group by expression" exception was thrown, see my sql statement below:
INSERT INTO RAWDATA_FACT
(
LINEITEMID
,CALENDARYEAR
,CALENDARQUARTER
,CALENDARMONTH
,DEPARTMENTID
,PRODUCTID
,DEALERID
,ACTUALVALUE
,TARGETVALUE
,AGGREGATION
,TODATE
,CREATEDATE
,BATCH_ID
)
select parentid
,calendaryear
,calendarquarter
,calendarmonth
,departmentid
,productid
,dealerid
,sum(case when unaryoperator = '-' then actualvalue * (-1)
when unaryoperator = '~' then actualvalue * 0
else actualvalue
end
) actualvalue
,sum(case when unaryoperator = '-' then targetvalue * (-1)
when unaryoperator = '~' then targetvalue * 0
else targetvalue
end
) targetvalue
,aggregation
,todate
,sysdate createdate
,'201808' batch_id--v_batch_ID
from
(
select
x.parentid
, x.unaryoperator
, y.calendaryear
, y.calendarquarter
, y.calendarmonth
, y.departmentid
, y.productid
, y.dealerid
, y.actualvalue
, y.targetvalue
, y.aggregation
, y.todate
from
(select substr(lineitemid,instr(lineitemid,'_')+1) lineitemid,
parentid, unaryoperator from lineitem_temp where levelid = 14 /*v_cur_level*/) x
inner join
(select lineitemid,calendaryear, calendarquarter, calendarmonth, departmentid, productid, dealerid,
coalesce(actualvalue,0) actualvalue,coalesce(targetvalue,0) targetvalue,
aggregation, todate
from RAWDATA_FACT where BATCH_ID = '201808'/*v_batch_ID*/) y --eg. 201809
on x.lineitemid = y.lineitemid
--parent node's id contains "_" will not take part in calculation from current level to parent level
where regexp_like(x.parentid , '^\d+$') and not exists
--parent node contains formula will not participate calculation from current level to parent level
(select 1 from LINEITEM_TEMP where lineitemid = x.parentid and custommember is not null)
) t
GROUP BY
t.parentid
, t.calendaryear
, t.calendarquarter
, t.calendarmonth
, t.departmentid
, t.productid
, t.dealerid
, t.aggregation
, t.todate
;
who can tell me why? is there a way to insert the result into that table? If I run the select parts, it works fine, but if I want to insert the result into that table, it reports that exception.

Related

Insert occasionally missing rows

I am running below query, sometimes these query skip few records to insert into newordersholdentry and didn't get any error.
but if run same query again after finding it is missed some records for order, it will insert all.
Please let me know what could be the reason.
INSERT INTO newordersholdentry
(itemid,
lookupcode,
description,
gamacode,
ordered,
IsForceItem,
Scanned,
Location,
SortOrder
)
SELECT ID,
ItemLookupCode,
Description,
GamaCode,
SUM(Qty) AS Qty,
ForceItem,
0 AS Scanned,
SubDescription1,
Sortorder
FROM
(
SELECT Item.ID,
Item.ItemLookupCode,
Item.Description,
NewOrderItems.GamaCode,
NewOrderItems.Qty,
Item.SubDescription1,
Item.Binlocation,
ISNULL(
(
SELECT TOP (1) SortSno
FROM NewOrderPickPackSorting
WHERE(Bin = LEFT(Item.SubDescription1, 3))
), 99999) AS Expr1,
0 AS ForceItem,
p.sortorder
FROM NewOrderItems(NOLOCK)
INNER JOIN Item(NOLOCK) ON NewOrderItems.GamaCode = Item.SubDescription2
LEFT OUTER JOIN pickpath(NOLOCK) p ON concat(RTRIM(p.aisle), '-', p.section) = UPPER(LEFT(item.subdescription1, 6))
WHERE(NewOrderItems.Discontinue = 0)
AND (NewOrderItems.OrderID = 123456)
) AS t
Group by ID
, ItemLookupcode
, Description
, GAMACODE
, ForceItem
, Expr1
, BinLocation
, SubDescription1
, sortorder

Finding Median in Sql Server

I want to get the median of unitRate from [dbo].[ReplaceCost_DirectCost_Details] view in Microsoft Sql Server Management Studio. I already got Min,Max and avg of it.But do not know about median. I tried following code, but did not get median .Thanks in advacen for your help.
select
JobName as JobName
,Client as Client
,AssetClass as AssetClass
,AssetType as AssetType
,AssetSubType as AssetSubType
,Component as Component
,ComponentType as ComponentType
,ComponentSubType as ComponentSubType
,UnitRate AS UnitRate
,Max(UnitRate) over (partition by JobName,Client,AssetClass,AssetType,AssetSubType,Component,ComponentType,ComponentSubType) as [MaxFinalUnitRate]
,Min(UnitRate) over (partition by JobName,Client,AssetClass,AssetType,AssetSubType,Component,ComponentType,ComponentSubType) as [MinFinalUnitRate]
,AVG(UnitRate) over (partition by JobName,Client,AssetClass,AssetType,AssetSubType,Component,ComponentType,ComponentSubType) as [MeanFinalUnitRate]
,AVG (UnitRate) over (partition by JobName,Client,AssetClass,AssetType,AssetSubType,Component,ComponentType,ComponentSubType)as Median
from
(
Select top (10)
JobName as JobName
,Client as Client
,AssetClass as AssetClass
,AssetType as AssetType
,AssetSubType as AssetSubType
,Component as Component
,ComponentType as ComponentType
,ComponentSubType as ComponentSubType
,UnitRate AS UnitRate
,ROW_NUMBER () over (partition by JobName,Client,AssetClass,AssetType,AssetSubType,Component,ComponentType,ComponentSubType order by UnitRate) as [RowNum]
,COUNT(*) OVER (PARTITION BY JobName,Client,AssetClass,AssetType,AssetSubType,Component,ComponentType,ComponentSubType ) AS RowCnt
from [dbo].[ReplaceCost_DirectCost_Details] rdd
where client = 'APV_Ballina_Shire_Council_Old' and UnitRate is not Null and UnitRate <> 0
) x
WHERE RowNum IN ((RowCnt + 1) / 2, (RowCnt + 2) / 2)
EDIT
SQL Fiddle
CREATE TABLE Table1
([somevalue] int)
;
INSERT INTO Table1
([somevalue])
VALUES
(141),
(325),
(325),
(353),
(3166),
(325),
(207),
(141),
(3166),
(161)
;
Query 1:
with cte as (
select *
, row_number() over(order by somevalue) as RowNum
, count(*) over() as RowCnt
from table1
)
select
*
from CTE
WHERE RowNum IN ((RowCnt + 1) / 2, (RowCnt + 2) / 2)
| somevalue | RowNum | RowCnt |
|-----------|--------|--------|
| 325 | 5 | 10 |
| 325 | 6 | 10 |
Please consider the following small example. There are 7 rows of data, the median is the "midpoint" of those, so the where clause uses a row number compared to row count, and returns just that midpoint valuse. That value (67) repesents the median of that small sample.
SQL Fiddle
MS SQL Server 2014 Schema Setup:
CREATE TABLE Table1
([somevalue] int)
;
INSERT INTO Table1
([somevalue])
VALUES
(2),
(45),
(67),
(89),
(4567),
(6),
(1290)
;
Query 1:
with cte as (
select *
, row_number() over(order by somevalue) as RowNum
, count(*) over() as RowCnt
from table1
)
select
*
from CTE
WHERE RowNum IN ((RowCnt + 1) / 2, (RowCnt + 2) / 2)
Results:
| somevalue | RowNum | RowCnt |
|-----------|--------|--------|
| 67 | 4 | 7 |
(sorry for using a second answer, but it will get lost if just added to the earlier one)
I am really not certain what the expected output of your query is. But I note that you are using TOP(10) and for that to work you must have an order by otherwise the result is indeterminate for the first 10 rows.
While the following may produce many more rows than you need, perhaps it will help lead to a solution.
WITH Basis as (
SELECT
JobName
, Client
, AssetClass
, AssetType
, AssetSubType
, Component
, ComponentType
, ComponentSubType
, UnitRate
, ROW_NUMBER() OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType
ORDER BY UnitRate)
AS [rownum]
FROM [dbo].[ReplaceCost_DirectCost_Details] rdd
WHERE client = 'APV_Ballina_Shire_Council_Old'
AND UnitRate IS NOT NULL
AND UnitRate <> 0
)
, Top10s as (
SELECT
JobName
, Client
, AssetClass
, AssetType
, AssetSubType
, Component
, ComponentType
, ComponentSubType
, UnitRate
, rownum
, COUNT(*) OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType)
AS rowcnt
FROM Basis
WHERE rownum <= 10
)
, Medians as (
SELECT
JobName
, Client
, AssetClass
, AssetType
, AssetSubType
, Component
, ComponentType
, ComponentSubType
, AVG(UnitRate) AS Median
FROM Top10s
WHERE RowNum IN ((RowCnt + 1) / 2, (RowCnt + 2) / 2)
GROUP BY
JobName
, Client
, AssetClass
, AssetType
, AssetSubType
, Component
, ComponentType
, ComponentSubType
, AVG(UnitRate)
)
SELECT
JobName
, Client
, AssetClass
, AssetType
, AssetSubType
, Component
, ComponentType
, ComponentSubType
, UnitRate
, rownum
, rowcnt
, MAX(UnitRate) OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType) AS [maxfinalunitrate]
, MIN(UnitRate) OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType) AS [minfinalunitrate]
, AVG(UnitRate) OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType) AS [meanfinalunitrate]
, Medians.Median
FROM Top10s t
JOIN Medians m ON t.JobName = m.JobName
AND t.Client = m.Client
AND t.AssetClass = m.AssetClass
AND t.AssetType = m.AssetType
AND t.AssetSubType = m.AssetSubType
AND t.Component = m.Component
AND t.ComponentType = m.ComponentType
AND t.ComponentSubType = m.ComponentSubType
;

ORA-30926: unable to get a stable set of rows in the source tables

I have a customer who gets: ORA-30926: unable to get a stable set of rows in the source tables:
Log show error Massage Error (30926)
13:52:19 (00:00:02.406) ERROR : Error (30926) (00:00:02.406) ORA-30926: Stabile Zeilengruppe in den Quelltabellen kann nicht eingelesen werden
TS03_MIN0100: UpdTable failed. Update inv_value in cMinTimeTable:
MERGE INTO HUBWBPMS5_ENTTS03005400223 a USING ( SELECT DISTINCT a.inv_value +
( a.inv_value_sum - h.inv_value ) AS inv_value , a.rowid xzfd_rid
FROM HUBWBPMS5_ENTTS03005700223 h , HUBWBPMS5_ENTTS03005400223 a
WHERE a.voucher_no = h.voucher_no AND a.sequence_no = h.max_seq_no
AND a.client = h.client ) xzfd_t ON ( xzfd_t.xzfd_rid = a.rowid )
WHEN MATCHED THEN
UPDATE
SET a.inv_value = xzfd_t.inv_value
I have checked for duplicate values in the tables but cant find anything unusual.
Maybe someone has an idea that could be useful.
The query is:
Query causing error (temp table):
INSERT INTO HUBWBPMS5_ENTTS03005700228 ( agg_flag , ace_code , activity , category , client , cost_dep , description , dim1 , dim2 , dim3 , dim4 , inc_ref , inv_value , max_seq_no , pd , period , project , resource_id , resource_typ , trans_date , unit , voucher_no , work_order , work_type )
SELECT agg_flag , ace_code , activity , category , client , cost_dep , description , dim1 , dim2 , dim3 , dim4 , inc_ref , SUM ( inv_value ) inv_value , max_seq_no , pd , period , project , resource_id , resource_typ , trans_date , unit , voucher_no , work_order , work_type
FROM HUBWBPMS5_ENTTS03005400228
WHERE agg_flag = 1
GROUP BY agg_flag , ace_code , activity , category , client , cost_dep , description , dim1 , dim2 , dim3 , dim4 , period , trans_date , voucher_no , max_seq_no , inc_ref , pd , project , resource_id , resource_typ , unit , work_order , work_type
When you get that error, it will be from a MERGE statement, and it indicates that there are multiple rows in the source dataset that match to a row you're joining to in the target table, and as such, Oracle doesn't know which one to use to do the update.
Taking your merge statement:
MERGE INTO HUBWBPMS5_ENTTS03005400223 a
USING (SELECT DISTINCT a.inv_value + ( a.inv_value_sum - h.inv_value ) AS inv_value,
a.rowid xzfd_rid
FROM HUBWBPMS5_ENTTS03005700223 h,
HUBWBPMS5_ENTTS03005400223 a
WHERE a.voucher_no = h.voucher_no
AND a.sequence_no = h.max_seq_no
AND a.client = h.client) xzfd_t
ON (xzfd_t.xzfd_rid = a.rowid)
WHEN MATCHED THEN
UPDATE SET a.inv_value = xzfd_t.inv_value;
it looks like the join between the two tables HUBWBPMS5_ENTTS03005700223 and HUBWBPMS5_ENTTS03005400223 in the xzfd_t subquery causes multiple rows to be returned for one or more of the HUBWBPMS5_ENTTS03005400223 rows (ie. you get multiple rows returned for at least one a.rowid).
To check this, run:
SELECT xzfd_rid,
COUNT(*) cnt
FROM (SELECT DISTINCT a.inv_value + ( a.inv_value_sum - h.inv_value ) AS inv_value,
a.rowid xzfd_rid
FROM HUBWBPMS5_ENTTS03005700223 h,
HUBWBPMS5_ENTTS03005400223 a
WHERE a.voucher_no = h.voucher_no
AND a.sequence_no = h.max_seq_no
AND a.client = h.client)
GROUP BY xzfd_rid
HAVING COUNT(*) > 1;
In order to fix this, you'd need to make the xzfd_t subquery return a single row for each xzfd_rid. Possibly using row_number() to pick a single row, or an aggregate query to sum up all the h.inv_value fields per a.rowid instead of the DISTINCT.

Order by logic for a forum thread

I have three columns
ThreadID
DateTime
CommentID
ReplyCommentID
Query
WITH CTE AS ( SELECT CommentID ,
CommentUserName,
ReplyCommentID ,
CommentID AS ThreadID ,
CAST( CommentID AS VARCHAR( MAX ) ) AS PathStr,
HtmlComment ,
CommentPostDocumentID ,
CommentIsApproved,
CommentDate
FROM Blog_CommentDetails AS T WITH(NOLOCK)
WHERE ReplyCommentID IS NULL
UNION ALL
SELECT T.CommentID ,
T.CommentUserName,
T.ReplyCommentID ,
CTE.ThreadID ,
PathStr + '-'+ CAST( T.ReplyCommentID AS VARCHAR( MAX ) ) AS PathStr,
T.HtmlComment ,
t.CommentPostDocumentID ,
t.CommentIsApproved,
T.CommentDate
FROM Blog_CommentDetails AS T WITH(NOLOCK)
JOIN CTE
ON T.ReplyCommentID = CTE.CommentID
WHERE T.ReplyCommentID IS NOT NULL)
SELECT *
FROM CTE
WHERE CommentPostDocumentID = 15 AND CommentIsApproved=1
ORDER BY ThreadID, PathStr ,
CommentDate DESC;
I need to order by ThreadID ascending first
Then i need to order by CommentID ascending second
Then i need to order by date descending third
But one condision, when there is commenid and replycommendid matches for two rows, rows with commenid should be first.
How can i write an order by for this?
ORDER BY ThreadID,CommentID,DateTime desc,
IF(ReplyCommentID == CommentID)
then
rows with commentid should be first
Current result:
But the expected result is:
You can use a calculated value for ordering; However, as calculation requires attributes from separate rows, these rows have first to be combined.
Without demo data in textual form, which I could take over to my environment, it's a bit hard to test.
The following schema is very close to your requirements, if we consider a as representing CommentId and b standing for ReplyCommentID:
create table test (
a int,
b int
);
insert into test (a,b) values (1,null), (2,1), (3,2), (4,1);
select distinct test.a as a, test.b as b, case when (test.b=test2.a or test.b is null) then 0 else 1 end as priority
from test left join test test2 on test.b = test2.a and test2.b is null
order by priority,a,b
Note that the order compared to an order by a,b changes analogously to what you expect in your sample data.
Givent that, when applying to your query (after the WITH CTE...-part), it should look as follows. As mentioned above, I cannot test it, so please do not throw stones on me if it does not work immediately:
SELECT distinct cte.*, case when (cte.ReplyCommentID =cte2.CommentId or cte.ReplyCommentID is null) then 0 else 1 end as priority
FROM CTE left join CTE cte2 on cte.ReplyCommentID = cte2.CommentId and cte2.ReplyCommentID is null
WHERE CommentPostDocumentID = 15 AND CommentIsApproved=1
ORDER BY ThreadID, priority, CommentId, PathStr , CommentDate DESC;
The following extensive example will walk through a tree of comments based on CommentID and ReplyCommentID (which serves as the ParentID). Children of the same ReplyCommentID are ordered by CommentDate DESC:
DECLARE #Table TABLE (
CommentID INT,
ReplyCommentID INT,
CommentDate DATETIME
);
INSERT INTO #Table VALUES
(140,NULL, CAST('20170109' AS DATETIME))
,(141,NULL, CAST('20170110' AS DATETIME))
,(142,141, CAST('20170111' AS DATETIME))
,(143,141, CAST('20170112' AS DATETIME))
,(144,141, CAST('20170113' AS DATETIME))
,(145,144, CAST('20170114' AS DATETIME))
,(146,NULL, CAST('20170115' AS DATETIME));
WITH [Statistics] AS (
SELECT Records.CommentID, Records.ReplyCommentID
, COUNT(Children.CommentID) AS NrOfChildren
, ROW_NUMBER() OVER (PARTITION BY Records.ReplyCommentID ORDER BY Records.CommentDate DESC) AS NthChild
, COUNT(Records.CommentID) OVER (PARTITION BY Records.ReplyCommentID) AS NrOfSiblings
FROM #Table Records
LEFT JOIN #Table Children ON Records.CommentID = Children.ReplyCommentID
GROUP BY Records.CommentID, Records.ReplyCommentID, Records.CommentDate
)
, Tree AS (
SELECT *
, 1 AS [Order]
, 0 AS [Rerouting]
, CAST(-1 AS INT) AS ReroutedFromNthChild
FROM [Statistics] AS TreeNode
WHERE ReplyCommentID IS NULL AND NthChild = 1
UNION ALL
SELECT NextNode.*
, TreeNode.[Order] + 1 AS [Order]
, CASE
WHEN (TreeNode.NrOfChildren = 0 AND TreeNode.NthChild = TreeNode.NrOfSiblings AND TreeNode.ReplyCommentID = NextNode.CommentID)
OR (TreeNode.Rerouting = 1 AND TreeNode.ReroutedFromNthChild = TreeNode.NrOfChildren AND TreeNode.ReplyCommentID = NextNode.CommentID)
THEN 1
ELSE 0
END AS [Rerouting]
, CAST(TreeNode.NthChild AS INT) AS ReroutedFromNthChild
FROM Tree AS TreeNode
JOIN [Statistics] AS NextNode
--Has children, so select first child
ON (TreeNode.Rerouting = 0 AND TreeNode.NrOfChildren > 0 AND NextNode.NthChild = 1 AND TreeNode.CommentID = NextNode.ReplyCommentID)
--Has no children, so select next sibling
OR (TreeNode.Rerouting = 0 AND TreeNode.NrOfChildren = 0 AND TreeNode.NthChild + 1 = NextNode.NthChild AND (TreeNode.ReplyCommentID = NextNode.ReplyCommentID OR (TreeNode.ReplyCommentID IS NULL AND NextNode.ReplyCommentID IS NULL)))
--Has no children or following siblings, so retrace the step (reroute)
OR (TreeNode.Rerouting = 0 AND TreeNode.NrOfChildren = 0 AND TreeNode.NthChild = TreeNode.NrOfSiblings AND TreeNode.ReplyCommentID = NextNode.CommentID)
--Was rerouting but has children, so back on track and follow the next child
OR (TreeNode.Rerouting = 1 AND TreeNode.ReroutedFromNthChild < TreeNode.NrOfChildren AND TreeNode.ReroutedFromNthChild + 1 = NextNode.NthChild AND TreeNode.CommentID = NextNode.ReplyCommentID)
--Was rerouting and has no other children, so continue rerouting
OR (TreeNode.Rerouting = 1 AND TreeNode.ReroutedFromNthChild = TreeNode.NrOfChildren AND TreeNode.ReplyCommentID = NextNode.CommentID)
--Rerouted to the top without children left, jumping to the next sibling
OR (TreeNode.Rerouting = 1 AND (TreeNode.ReroutedFromNthChild = TreeNode.NrOfChildren OR TreeNode.NrOfChildren = 0) AND TreeNode.NthChild + 1 = NextNode.NthChild AND TreeNode.ReplyCommentID IS NULL AND NextNode.ReplyCommentID IS NULL)
)
select *
from Tree
where Rerouting = 0
ORDER BY [Order]

Calculating using Variables in MYSQL query

hope you can help, this is driving me up the wall
I need to calculate the percentage of times a question has been failed, but this needs to be narrowed down by the geographical area, and product these questions are being asked against.
I have :
$CA002 = "( SELECT ROUND(100 * (SELECT count(CA002Result) from Data_Table where (CA002Result='Fail'))/count(CA002Result),2) from Data_Table) AS 'CA002 %'";
Which 'works' but just calculates against the whole set of records as an 'overall'
I'm trying :
$CA001 = "( SELECT ROUND(100 * (SELECT count(CA001Result) from Data_Table where (CA001Result='Fail' AND Area ='$Area'))/count(CA001Result) from Data_Table WHERE (Area='$Area'),2) AS 'CA001 %'";
And Also :
$CA001 = "( SELECT ROUND(100 * (SELECT count(CA001Result ) from Data_Table where (CA001Result='Fail' AND Product='$product' AND Area='$Area'))
/ count(CA001Result WHERE Product = '$product' AND Area='$Area'),2) from Data_Table) AS 'CA001 %'";
and am just getting errors no matter what I try, I just can't seem to work out what I need to put where.
Any great GREATLY apprteciated, thankyou.
Try this
//Filter by Area
create table t( id int, answer varchar(10),Area varchar(10));
insert into t select 1 , 'pass' , 'Area1';
insert into t select 2 , 'pass' , 'Area1';
insert into t select 3 , 'fail' , 'Area1';
insert into t select 4 , 'fail' , 'Area1';
insert into t select 5 , 'fail' , 'Area1';
insert into t select 6 , 'fail' , 'Area2';
SELECT
(x.TotalFailedAnswerRecord * 100) /y.TotalRecord AS Fail_percent
FROM
( SELECT Area,TotalFailedAnswerRecord = COUNT(answer)
FROM t
WHERE answer='fail' AND Area = 'Area1'
GROUP BY Area
)x
INNER JOIN
( SELECT Area,TotalRecord = COUNT(answer)
FROM t
WHERE Area = 'Area1'
GROUP BY Area
)y ON x.Area =y.Area
//Result
Fail_percent
-------------
60
//Filter by Area,Product
create table t( id int, answer varchar(10),Area varchar(10),Product varchar(10));
insert into t select 1 , 'pass' , 'Area1' ,'Product1';
insert into t select 2 , 'fail' , 'Area1' ,'Product1';
insert into t select 3 , 'fail' , 'Area1' ,'Product1';
insert into t select 4 , 'fail' , 'Area1' ,'Product1';
insert into t select 5 , 'fail' , 'Area1' ,'Product2';
insert into t select 6 , 'fail' , 'Area2' ,'Product2';
SELECT
(x.TotalFailedAnswerRecord * 100) /y.TotalRecord AS Fail_percent
FROM
( SELECT Area,Product,TotalFailedAnswerRecord = COUNT(answer)
FROM t
WHERE answer='fail' AND Area = 'Area1' AND Product = 'Product1'
GROUP BY Area,Product
)x
INNER JOIN
( SELECT Area,Product,TotalRecord = COUNT(answer)
FROM t
WHERE Area = 'Area1' AND Product = 'Product1'
GROUP BY Area,Product
)y ON x.Area =y.Area AND x.Product = y.Product
//Result
Fail_percent
-------------
75
Hope this helps