sum of calculated expression in rdlc report - report

I want sum of salary column:
this is expr for salary column:
=iif(fields!Items.Value="A",(cdec(sum(fields!sumofincome.Value)/1000*3)), iif(fields!Items.Value="B",(cdec(sum(fields!sumofincome.Value)/1000*1.5)),iif(fields!Items.Value="C",(cdec(sum(fields!sumofincome.Value)/1000*0.5)),0)))`

Related

Using Count Average and median in SQL case when statement

I am trying to create a query where if the student id count is 2, then the output should be the average score of those two.
If the student id count is more than 2, then the output should be the median score of those students. I'm not getting the desired output
Here is the case-when statement that I am using:
case when (count(Student.STUDENT_ID) = 2) THEN AVG(Scores.TEST_GROWTH_PERCENTILE)
else PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY TEST_GROWTH_PERCENTILE) OVER (PARTITION BY dates.local_school_year,grade.domain_decode)
END

How to average at two levels?

I am trying to average at multiple levels but am able to for one level only:
SELECT group_id,
STRFTIME("%W", date) as week_num,
AVG(count_value) as value FROM counts
GROUP BY week_num;
I get:
How to get averages for each group_id based on average of each week_num? I have to calculate average at week_num level and then average at group_id level. Expected result:
Use a subquery to calculate averages at week_num level and then calculate the average at group_id level in the outer query:
SELECT group_id, AVG(value)
FROM (
SELECT group_id,
STRFTIME("%W", date) as week_num,
AVG(count_value) as value FROM counts
GROUP BY group_id, week_num
)
GROUP BY group_id;

UDF for calculating median of a column in a table - pl/sql

Please help me.
I need an UDF for calculating median of a column (salary) in ascending order.
I only need user defined function for calculating median.
A general query to find a median value is to use one of the windowing functions :
PERCENTILE_CONT
PERCENTILE_DISC
With the WITHIN GROUP clause associated.
As an example, to find the median salay from a table of salary, you can write :
SELECT *, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) OVER () AS MEDIAN_SALARY
FROM SalariesTable

How Correlated sub query works

Would anyone please explain how the below query works, this query is to find the Nth highest salary.
Will this works like bubble sort, just like taking one column of outer tab at a time and compare with inner table..? requesting you to explain with example.
Select distinct(salary)
from emp e
where &n = (
Select count(distinct(salary))
from emp
where e.salary<= salary);
Let's take this example: http://sqlfiddle.com/#!4/b863c9/9
Table
create table salary (salary int);
insert into salary values (100);
insert into salary values (200);
insert into salary values (300);
insert into salary values (400);
insert into salary values (400);
insert into salary values (500);
insert into salary values (600);
insert into salary values (700);
insert into salary values (800);
insert into salary values (900);
2nd highest
Select distinct(salary)
from salary e
where 2 = (
Select count(distinct(salary))
from salary
where e.salary <= salary);
What is the sub query doing?
For each distinct salary in the outer query, the sub query will execute. select distinct(salary) from salary will list out all the distinct salary in no order.
For each of those salaries, the sub query will filter data higher than salary of the outer query's salary. Then it will count distinct salaries. Let's do a run through:
When outer query has salary of 100, sub query execute something like this: select count(distinct(salary)) from salary where salary >= 100 resulting in 9. That means, there are 9 distinct salaries >= 100.
When outer query has salary of 200, sub query executes select count(distinct(salary)) from salary where salary >= 200. The result is 8.
As the query goes over and over again to the next salaries, it will come to a salary of 800. Sub query select count(distinct(salary)) from salary where salary >= 800 results in 2. At this point, the where clause is satisfied for the outer query and the salary is printed.
As far as the algorithm, it depends on whether there's index or not and whether you use order or not.

Sum of a calculated textbox in ssrs reporting in asp.net

I want to calculate the sum of a calculated textbox i.e
Table1 has two columns colA bind with database [socre] and
ColB has an expression
[exp] i.e [score]/sum[score]*100
what i want is
TOTAL of colB sum[colB]
Please suggest me any suggestion.

Resources