SSRS How to replicate Column Total in each row - reporting-services

Team Sales TotalSales
A 10 70
B 25 70
C 30 70
D 5 70
I have a dataset for an example please refer the above. The total sales for all 4 teams are 70. I wanted to replicate Grandtotal e.g.70 for each Row on a Matrix. Is it possible? Thank you in advance.

Just add a column with the expression
=SUM(Fields.Sales.Value, "mydataSetname")
Remember to click the check mark if you think an answer has solved you question instead of just voting up. Remember and answer is good if if answers you actual question, if you have left information out of your question and you still have an issue, start a new question.

Related

How to sum specific rows and columns in SQL?

pnr mnd pris
1 1 600
1 7 900
2 1 600
2 7 600
3 1 40
3 7 40
I have trouble how to sum specific rows on the columns. Looking at the above, the table is called travel and it has 3 columns:
pnr - Personal Number
mnd - Month
Pris - Price
So what I want is to sum total of the price for the a specific month, so in this case, it should be 1240 USD and month 1. For the month 7, it should be 1540 USD.
I have trouble to do the query correct. So far from I have tried is this:
SELECT t.rnr, t.mnd, SUM(t.pris)
FROM travel AS t
WHERE t.mnd = 1
The result I get is 3720 USD which I have no idea how the SQL managed to calculate this for me.
Appreciate if someone could please help me out!
For this you need to drop the pnr column from the output (it is not relevant and will cause your data to split) and add a GROUP BY:
SELECT t.mnd, SUM(t.pris)
FROM travel AS t
WHERE t.mnd = 1
GROUP BY t.mnd
Live demo: https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=b34ec2bb9c077c2d74ffc66748c5c142
(The use of an aggregate function without grouping, as you've got now, is not a standard SQL feature and can often be turned off in MySQL. If turned on, you might not always get the result you expected/intended.)
just group your result with mnd column
SELECT t.mnd, SUM(t.pris)
FROM travel AS t
group by t.mnd

How to retrieve rows with particular number of different column values in SQL?

I am implementing an exam portal. I have teacher and student as users.
Teachers generate question set for particular subject for taking exam. He has 4 options based on exam full marks ( 20 marks, 50 marks, 80 marks and 100 marks ), duration is also fixed during marks selection as 30 min, 60 min, 90 min, and 120 mins.
I have a question table. That has field for question, answer and level(Easy, Medium, Hard). Easy question 1 marks, Medium level question 2 marks and Hard level question 3 marks.
Any number of questions could be added to the set by teacher. And questions will be fetched randomly from database. Also each student should get 6 easy, 4 medium and 2 hard level question in a set of 20 marks, i.e. total 12 questions to be fetched randomly following criteria of levels. Similarly, for 50 marks set, 15 EASY level, 10 MEDIUM level and 3 HARD level questions have to be fetched and so on.
Please avoid all other conditions you think must be present and help me with forming an mysql query or just help me with some clues of what sql clause should I use.
I'd use a union select two times additionally to first query so each select gets a set by question level.
From just the title, I would guess you are looking for
HAVING COUNT(col) = 7

MySQL finding what rank a number has in multiple columns

I've looked a lot on here to see if this has been asked but I couldn't find it. So I'm sorry if it has been answered before.
My question is very basic but for some reason I cannot seem to get it.
I have the following table:
ID Mike Carl Steve Josh
1 2$ 3$ 1$ 5$
2 4$ 5$ 1$ 2$
So what I need is to know what position out of all ID's does Mike rank from lowest to highest? This would mean for ID 1 it would yield position 2 because he is the second lowest. For ID 2 it would yield position 3 because he is the third lowest. This will go on for about 200000 positions for about 20 people but I just lowered it to simplify it.
Please let me know if you have any ideas and thank you so much in advance for all the help!
Just exported to excel and used rank on each column.

Using two columns to obtain count on another in SQL

I have a simple question that I wasn't really sure how to search for (or title!). I apologize if this has been asked a million times. For the following table, how do I generate a report that will detail the number of companies that a person has worked for and how many people have also worked for that same number? So, for example, this table should return:
people, companiesperperson
1, 1
2, 2
1, 3
for the following table called personalinfo:
id_number first last company
1 John Doe Intel
2 John Doe Microsoft
3 Phil Jenkins Amgen
4 Phil Jenkins Bayer
5 Phil Jenkins Sanofi
6 Josh Edwards Walgreens
7 Amy Dill URS
8 Amy Dill ARCADIS
Let me know if this is still confusing and if I can further clarify what I am looking to do.
Thanks!
This is a rough estimate of the query but
SELECT count as companiesperperson, COUNT(first, last) as people FROM
(SELECT COUNT(company) as count, first, last FROM personalinfo GROUP BY (first, last)) as a
GROUP BY count
To explain the query first in the subquery we are asking for the names and count of companies after splitting up all the rows by names
Then in the outer query we split up all the rows by their count and ask how many unique names can be found in each group.
There may be a few syntax errors I've left straggling but the group by feature is really what's essential to understanding how to solve this question.

display average of two rows

studentname I II
Vivek Johari 30 20
Chandra Singh 30 20
Avinash Dubey 30 25
Pankaj Kumar 33 29
I have a table named student with details as above. I want to find the average of column I and II and display it on a new column using pivot. Please help me to solve this using pivot..
May I use any sub query to solve this using pivot...
your questions is not specific enough.
Do you want the total average of both columns? just do
select avg (I), avg(II)
from your_table
if you want just one value, you can do:
select (avg (I) + avg(II))/2
from your_table