|
|
Question : anyone can help me about how to complete the following 2 SQLstatements. any idea on this will be highly appreciated!
|
|
|
|
the following is my table, each transaction happened will record in this table. now I want get some analysis data by SQL, requirement as below: Requirement 1: 1, obtain all total of transcation total request, just SQL as: select sum("Total_Requests") as "Total_Trans_Reqs" from "Transaction"
2, obtain each sum of each transaction total request, SQL as: select "Transaction", sum("Total_Request") as "Single_Trans_Total_Reqs" from "Transaction" group by "Transaction"
3, this percent is what I need, "Single_Trans_Total_Reqs" / "Total_Trans_Reqs" = ?% how could I write it in one SQL to run and get this result for my program. many thanks?
Requirement 2: 1, obtain all "Transaction“ happen times: SQL as: select count("Transaction") as "All_Trans_Total_count" from "Transaction"
2, obtain each "Transaction" happen times, SQL as: select "Transaction", count("Transaction") as "Singe_Trans_count" from "Transaction" group by "Transaction"
3, the percent is what I want: "Single_Trans_count" / "All_Trans_Total_count" = ?%
table "Transaction" ("Transaction" VARCHAR(128) , "Timestamp" CHAR(16) , "Data_Interval" INTEGER , "Percent_Failed" DECIMAL(31,3) , "Percent_Slow" DECIMAL(31,3) , "Percent_Good" DECIMAL(31,3) , "Percent_Available" DECIMAL(31,3) , "Average_Response_Time" DECIMAL(31,3) , "Failed_Requests" INTEGER , "Total_Requests" INTEGER , "Slow_Requests" INTEGER , "Good_Requests" INTEGER , "Data_Collector_Type" VARCHAR(32) , "Rank" DECIMAL(31,3) , "Total_Server_Response_Time" DECIMAL(31,3) , "Total_Connect_Time" DECIMAL(31,3) , "Total_DNS_Time" DECIMAL(31,3) , "Total_Resolve_Time" DECIMAL(31,3) , "Average_Server_Response_Time" DECIMAL(31,3) , "Average_Connect_Time" DECIMAL(31,3) , "Average_DNS_TIME" DECIMAL(31,3) , "Average_Resolve_Time" DECIMAL(31,3) )
|
|
|
|
Answer : anyone can help me about how to complete the following 2 SQLstatements. any idea on this will be highly appreciated!
|
|
|
|
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
|
select x.transaction,(single_trans_total_reqs*100.00)/total_trans_req
,(single_trans_count*100.00)/all_trans_total_count
from (
select sum(total_requests) as Total_trans_reqs
,count(*) as all_trans_total_count
from transaction
) as Y.
(
select a.transaction,sum(total_requests) as single_trans_total_reqs
,count(*) as single_trans_count
from transaction as a
group by a.transaction
) as x
order by 1
|
|
|
|
|
|