I have the following coefficient table for exams.
val_disp | val_ret
%0 | 0
%10 | 0.1
%20 | 0.2
%30 | 0.3
%40 | 0.4
%50 | 0.5
%60 | 0.6
%70 | 0.7
%80 | 0.8
%90 | 0.9
%100 | 1
And I listing these values as lov in select lists like this
https://imgur.com/qslkXzt
Is it possible to cascade these values to sum up %100? For ex... if I choose %30 for midterm and %40 for final, max available value for assignment can be cascaded to %30 by summing up 2 item value?
And how can I use val_ret of selected list item in sql query?
Or am I in a realy realy wrong way?
Set "Cascading LOV parent item(s)" property to previous LOVs.
In a LOV query, reference previously set values.
For example:
LOV_1:
select '%' || 10 * (level - 1) val_disp,
(level - 1) / 10 val_ret
from dual
connect by level <= 11;
LOV_2: cascading LOV is LOV_1
select '%' || 10 * (level - 1) val_disp,
(level - 1) / 10 val_ret
from dual
connect by level <= (1 - :LOV_1) * 10 + 1;
LOV_3: cascading LOVs are LOV_1 and LOV_2
select '%' || 10 * (level - 1) val_disp,
(level - 1) / 10 val_ret
from dual
connect by level <= (1 - (:LOV_1 + :LOV_2)) * 10 + 1;
Related
First of all please accept my apologize because of bad english. Also I'm new to this portal. I hope you'll help me for my questions.
I have two questions in Oracle.
How to find the number of '*' in each column on the table.
how to find the total number of '*' in the table.
The first question answer will be 2 2 3
The second one answer will be 7.
Thanks in advance to spend your valuable time to answer my questions!
C1 C2 C3
* 1 1
0 0 *
1 * *
* * *
Use conditional aggregation to count the stars in each column and for the total stars just add the previous totals:
SELECT COUNT(CASE c1 WHEN '*' THEN 1 END) AS c1_stars,
COUNT(CASE c2 WHEN '*' THEN 1 END) AS c2_stars,
COUNT(CASE c3 WHEN '*' THEN 1 END) AS c3_stars,
COUNT(CASE c1 WHEN '*' THEN 1 END)
+ COUNT(CASE c2 WHEN '*' THEN 1 END)
+ COUNT(CASE c3 WHEN '*' THEN 1 END) AS total_stars
FROM table_name
select sum(
case when c1='*' then 1
else 0 end) c1_cnt,
sum(
case when c2='*' then 1
else 0 end) c2_cnt,
sum(
case when c3='*' then 1
else 0 end) c3_cnt,
sum(
regexp_count(c1||c2||c3,'\*')) cnt_total_stars
from cnt_star;
C1_CNT
C2_CNT
C3_CNT
CNT_TOTAL_STARS
2
2
3
7
For the original table -
select * from cnt_star;
C1
C2
C3
*
1
1
0
0
*
1
*
*
*
*
*
I am dealing with a huge dataframe containing 3 columns and 5 Bil. rows. The size of the data is 360 GB. For the analysis of the Data I am using the following set-up:
-Jupyternotebooks running on a AWS r4.16xlarge
-PySpark Kernel
The table called customer_sales looks similar to the following example:
+--------------------+----------+-------+
| business_unit_id | customer | sales |
+--------------------+----------+-------+
| 1 + a + 5000 +
| 1 + b + 2000 +
| 1 + c + 3000 +
| 1 + d + 5000 +
| 2 + f + 600 +
| 2 + c + 7000 +
| 3 + j + 200 +
| 3 + k + 800 +
| 3 + c + 4500 +
Now I want to get for each business_unit_id the customer with the highest sales. If there is a draw in sales between several customer I want to get them all. The information should be stored in a table called best_customers_for_each_unit. So for the above illustrated example the table best_customers_for_each_unit looks as follows:
+--------------------+----------+-------+
| business_unit_id | customer | sales |
+--------------------+----------+-------+
| 1 + a + 5000 +
| 1 + d + 5000 +
| 2 + c + 7000 +
| 3 + c + 4500 +
In a second step I want to count how often it happens that a customer is the one with the highest sales in a specific business_unit_id. The output of this query will be:
+----------+-------+
| customer | count |
+----------+-------+
| a + 1 +
| b + 1 +
| c + 2 +
For the first query I used spark.sql with window functions. The used query looks as follows:
best_customers_for_each_unit = spark.sql("""
SELECT
business_unit_id,
customer,
sales
FROM (
SELECT
business_unit_id,
customer,
sales,
dense_rank() OVER (PARTITION BY business_unit_id ORDER BY sales DESC)as rank
FROM customer_sales) tmp
WHERE
rank =1
""")
For the second query I used the following PySpark snipped:
best_customers_for_each_unit.groupBy("customer").count()
My queries do actually work, but it takes ages to only process a minor part of the data. So do you know any efficient way to do such queries with PySpark?
Regards
C1 C2 C3 C4 C5 C6 C7 C8 Total **Percentages**
======================================================
R1 6 1 8 8 2 1 1 0 27 **60%**
R2 0 0 0 5 1 1 0 0 7 **16%**
R3 2 0 3 2 0 1 0 0 8 **18%**
R4 2 0 0 1 0 0 0 0 3 **7%**
TTL10 1 11 16 3 3 1 0 45 **100%**
How to calculate the individual row percentages in SSRS
Thank you.
If you're not filtering your dataset, you could use the Dataset sum to get the overall total and use that as the denominator in your expression.
If your table is a matrix with the C1 - C8 all coming from one field, then your formula would just be:
=Sum(Fields!YourField.Value) / Sum(Fields!YourField.Value, "Dataset1")
If the C1 - C8 fields are in separate fields, you can use the same expression used for your total column as the numerator and then divide by the SUM of all the other fields.
=Sum(Fields!C1.Value + Fields!C2.Value + Fields!C3.Value + Fields!C4.Value + Fields!C5.Value + Fields!C6.Value + Fields!C7.Value + Fields!C8.Value)
/
Sum(Fields!C1.Value + Fields!C2.Value + Fields!C3.Value + Fields!C4.Value + Fields!C5.Value + Fields!C6.Value + Fields!C7.Value + Fields!C8.Value, "Dataset1"))
I will work on SQL rather on SSRS. Here is my approach. For SSRS here is the link.
DECLARE #YourTable TABLE
(
Col INT
,Col1 INT
,Col2 INT
,Col3 INT
)
INSERT INTO #YourTable VALUES
(1 , 20, 10, 15)
,(2 , 30, 12, 14)
,(2 , 22, 2, 4)
,(3 , 3, 10, 15)
,(5 , 5, 14, 14)
,(2 , 21, 32, 4)
SELECT * FROM #YourTable
; WITH CTE AS
(SELECT *,Col+Col1+Col2+Col3 AS SumCol FROM #YourTable)
SELECT *, CAST(SumCol*100.0 / SUM(SumCol) OVER() as DECIMAL(28,2)) FROM CTE
Here's another approach:
Create a row outside of the details group, above the first row of data.
Populate a Textbox in the new row =Sum(Fields!Total.Value). Rename the Textbox something unique, such as Denominator.
Hide the row.
For your percentage formula in the details row, use something like:
=Sum(Fields!Total.Value) / ReportItems!Denominator.Value
I don't know how to convert integer into percentage, please help me. Thank you
Here's the query:
SELECT 'Data' || ',' ||
TO_CHAR(D.DTIME_DAY,'MM/dd/yyyy') || ',' ||
NVL(o.CNT_OPENED,0) || ',' || --as cnt_opened
NVL(c.CNT_CLOSED,0) --as cnt_closed
FROM OWNER_DWH.DC_DATE d
LEFT JOIN (SELECT TRUNC(t.CREATE_TIME, 'MM') AS report_date,
count(*) AS cnt_opened
FROM APP_ACCOUNT.OTRS_TICKET t
WHERE t.CREATE_TIME BETWEEN SYSDATE -120 AND SYSDATE
GROUP BY TRUNC(t.CREATE_TIME, 'MM')) o
ON d.DTIME_DAY=o.REPORT_DATE
LEFT JOIN (SELECT TRUNC(t.CLOSE_TIME, 'MM') as report_date,
count(*) AS cnt_closed
FROM APP_ACCOUNT.OTRS_TICKET t
WHERE t.CLOSE_TIME BETWEEN SYSDATE -120 AND SYSDATE
GROUP BY TRUNC(t.CLOSE_TIME, 'MM')) c
ON D.DTIME_DAY=c.REPORT_DATE
WHERE d.DTIME_DAY BETWEEN SYSDATE -120 AND TRUNC(SYSDATE) -1 AND
d.DTIME_DAY = TRUNC(d.DTIME_DAY, 'MM') AND
TRUNC(d.DTIME_DAY,'MM')= d.DTIME_DAY
ORDER BY D.DTIME_DAY;
The output of that query:
Data,10/01/2013,219,201
Data,11/01/2013,249,234
Data,12/01/2013,228,224
Data,01/01/2014,269,256
example output that I need is like this:
Data,10/01/2013,219, 52%, 201, 45%
Data,11/01/2013,249, 75%, 234, 60%
.......
........
Formula:
create_time + close time = total / create_time (for cnt_opened each column) = percentage
create_time + close time = total / close_time (for cnt_closed each column) = percentage
Try this:
Basically just add the total of CNT_OPENED and CNT_CLOSED, then whichever you want to take the percentage of, multiply that by 100 and divide by the sum.
For instance, CNT_OPENED = 219 and CNT_CLOSED = 201 so the total is 420. Multiply CNT_OPENED by 100 and then divide by 420 -> (219 * 100) / 420 = 52. Do the same thing with CNT_CLOSED.
Note that this WILL result in an exception if both CNT_OPENED and CNT_CLOSED are 0.
SELECT 'Data'
||','||TO_CHAR(D.DTIME_DAY,'MM/dd/yyyy')
||','||NVL(o.CNT_OPENED,0) --as cnt_opened
||','||(NVL(o.CNT_OPENED,0) * 100) / (NVL(o.CNT_OPENED,0) + NVL(o.CNT_CLOSED,0)) || '%'
||','||NVL(c.CNT_CLOSED,0) --as cnt_closed
||','||(NVL(o.CNT_CLOSED,0) * 100) / (NVL(o.CNT_OPENED,0) + NVL(o.CNT_CLOSED,0)) || '%'
That will also potentially give you a million decimal places, so if you only want to take it out to a couple, simply use the TRUNC function and specify your precision (2 decimal places in this case):
TRUNC((NVL(o.CNT_OPENED,0) * 100) / (NVL(o.CNT_OPENED,0) + NVL(o.CNT_CLOSED,0)), 2)
I know the id of a specific document I want to show in my result set, but I don't know which page of the results it will be on. Is it possible with elastic search to tell it to return the page that a specific document is on?
My guess is this is not possible. My current approach is to run the query once loading just the documents ids and return a very large (all) result set for the query. I find the id in this list, then I run the query again loading all of the data I want to show on the page. I'd prefer not to run the query twice if I can avoid it.
I am using JAVA API and I am getting the index, type, id and source as follows.
SearchResponse response = client.prepareSearch().execute().actionGet();
SearchHit[] documents = response.getHits().getHits();
for(SearchHit document : documents)
{
System.out.println("document index :: " + document.getIndex());
System.out.println("document type :: " + document.getType());
System.out.println("document id :: " + document.getId());
System.out.println("document source JSON :: " + document.getSourceAsString());
}
I've faced quite similar challenge.
We have to figure out what's the clip position in some list.
It works with assumption that we sort by score and by document id.
Without sorting by id or anything else as second sorting rule it would not work this way.
Here's a PHP code overview of our's solution:
$clipScore = $this->getScore($clip);
$lowestPossibleHigherScore = $this->getLowestPossibleHigherScore($clipScore);
$countHigherScore = $this->countClipsWithMinScore($lowestPossibleHigherScore);
$countSameScoreAndHigherId = $this->countClipsWithMinScore($clipScore, $clip->getId());
$countHigherScoreAndHigherId = $countHigherScore;
if ($countHigherScore > 0) {
$countHigherScoreAndHigherId = $this->countClipsWithMinScore($lowestPossibleHigherScore, $clip->getId());
}
$position = $countHigherScore + ($countSameScoreAndHigherId - $countHigherScoreAndHigherId);
return $position;
And here are some notes why this works ;)
/**
* Considered test cases =D
*
* | Position | Score | ID |
* | 0 | 4.0 | 3 |
* | 1 | 3.2 | 1 |
* | 2 | 3.1 | 6 |
* | 3 | 2.5 | 5 |
* | 4 | 2.5 | 4 |
* | 5 | 2.5 | 2 |
* | 6 | 1.2 | 7 |
*
* findPosition(ID = 4)
*
* countAllMinScore(2.501) = 3 (A) // so it's best position is 3 (4th place)
* countAllMinScoreAndBiggerId(2.5, 4) = 2 (C) // "two" of same score and higher ID
* countAllMinScoreAndBiggerId(2.501, 4) = 1 (D) // "one" of higher score and higher ID
*
* $position (how to get "4"?) = 3 (A) + 1 (C - D) ??? YES !!!!
*
* // next case
* findPosition(ID = 5)
*
* countAllMinScore(2.501) = 3 (A)
* countAllMinScoreAndBiggerId(2.5, 5) = 1 (C)
* countAllMinScoreAndBiggerId(2.501, 5) = 1 (D)
*
* $position (how to get "3"?) = 3 (A) + 0 (C - D) = 3 ??? YES !!!!
*
* // next case
* findPosition(ID = 2)
*
* countAllMinScore(2.501) = 3 (A)
* countAllMinScoreAndBiggerId(2.5, 2) = 5 (C)
* countAllMinScoreAndBiggerId(2.501, 2) = 3 (D)
*
* $position (how to get "5"?) = 3 (A) + 2 (C - D) = 5 ??? YES !!!!
*
* /// next case
* findPosition(ID = 3)
*
* countAllMinScore(4.001) = 0 (A)
* countAllMinScoreAndBiggerId(4.0, 3) = 0 (C)
* countAllMinScoreAndBiggerId(4.001, 3) = 0 (D)
*
* $position (how to get "0"?) = 0 (A) + 0 (C - D) = 0 ??? YES !!!!
*
* /// next case
* findPosition(ID = 7)
*
* countAllMinScore(1.201) = 6 (A)
* countAllMinScoreAndBiggerId(1.2, 7) = 0 (C)
* countAllMinScoreAndBiggerId(1.201, 7) = 0 (D)
*
* $position (how to get "6"?) = 6 (A) + 0 (C - D) = 6 ??? YES !!!!
*
*
* /// next case
*
* | Position | Score | ID |
* | 0 | 4.0 | 3 |
* | 1 | 4.0 | 1 |
* | 2 | 3.1 | 6 |
* | 3 | 2.5 | 5 |
* | 4 | 2.5 | 4 |
* | 5 | 2.5 | 2 |
* | 6 | 1.2 | 7 |
*
* findPosition(ID = 3)
*
* countAllMinScore(4.001) = 0 (A)
* countAllMinScoreAndBiggerId(4.0, 3) = 0 (C)
* countAllMinScoreAndBiggerId(4.001, 3) = 0 (D)
*
* $position (how to get "0"?) = 0 (A) + 0 (C - D) = 0 ??? YES !!!!
*
* /// next case
* findPosition(ID = 1)
*
* countAllMinScore(4.001) = 0 (A)
* countAllMinScoreAndBiggerId(4.0, 1) = 1 (C)
* countAllMinScoreAndBiggerId(4.001, 1) = 0 (D)
*
* $position (how to get "1"?) = 0 (A) + 1 (C - D) = 1 ??? YES !!!!
*/