SSRS Group by & duplicate rows - reporting-services

[enter link description here][1]I have dataset from SQL like below:
Dataset
In ssrs, i need the report like below:
Result
I used the Table.Tried,
Option1: Applied Parent Row group for "Col1" ,child row group for "Col2" Hide duplicates in "Col3" based on "Col1" group.
Option 2:Applied Row group for "Col1" , Hide duplicates in "Col2" based on "Col1" group & Hide duplicates in "Col3" based on "Col1" group.
Option 3: =iif(Previous(Fields!col.Value)=Fields!col.Value , true, false) in column level.
i could not get expected result with above option.please suggest me

What you want like in your result picture isnt possible. You basically grouped Col1, Col2 and Col3 in one Tablix. Thats doesnt work.
You can group for example by Col1 and Col2, then you get
Test | A
Test | B
You can group by Col2 and Col3:
Test | X
Test | Y
Test | Z
If you group Col1 and Col2 and Col3 you get the whole table back, like nothing happened.
But you can group by Col1 and Col2 and aggregate (with Count) Col3. Like this:
Test | A | 3
Test | B | 3

Related

Google Query Language: How to select the min value?

I am doing some web scraping task, and I get prices from a website. The issue is that I would like to get the min between all options. For example: It will looks for one cellphone , which has 8GB and it is unlocked B, but I also need that it returns the min price between all options it finds. Google Query Language: How to select the min value?
This is my sheet. This is the google spreadsheet
=QUERY(ImportJSON(C2),"SELECT Col4,Col20 WHERE Col4 CONTAINS '8GB' AND Col4 CONTAINS 'Unlocked B' LIMIT 1 label Col4'',Col20''",1)
how can I modify that formula so it returns the min price? It's like a loop function, is that possible? regardless its color
For example, I want the function to look for the price, it already does, but I would like to get the lowest price it could finds, instead of the first price it finds and matches with the formula
Google-Query Language Reference
try:
=QUERY(IMPORTJSON(C2),
"select Col4,Col20
where Col4 contains '8GB'
and Col4 contains 'Unlocked B'
order by Col20
limit 1
label Col4'',Col20''", 1)
or:
=QUERY(IMPORTJSON(C2),
"select Col4,min(Col20)
where Col4 contains '8GB'
and Col4 contains 'Unlocked B'
group by Col4
order by min(Col20)
limit 1
label Col4'',min(Col20)''", 1)

Create a new column based on an absolute reference

I have created an SQl Query that gives me the results below
Product| Qty.Sold | Total Value
----------------------------
Men | 585 | 4750
Wom | 927 | 9235
Child | 587 | 6023
I need to create 2 additional columns next to Total Value.
For the new column 1
Formula is first value of Qty.Sold/Sum of Qty Sold.The same applies for corresponding rows(Wom,Child..)
Eg : 585/2561,927/2561....
For the new column 2
Formula is first value of Total Value/Sum of Total Value.The same applies for corresponding rows(Wom,Child..)
Eg : 4750/25726,9235/25726...
How Can I write a sql query to accommodate this new change
So something like this:
SELECT Product,Qty_sold,total_value,
Qty_sold/(select sum(Qty_sold) FROM (Your query here)) as Col1,
total_value/(select sum(total_value) FROM (Your query here)) as Col2
FROM (Your query here)
I assume you want something like this:
SELECT product, qty, value,
qty/(SELECT SUM(qty) FROM tbl) AS qty_ratio
value/(SELECT SUM(value) FROM tbl) AS value_ratio
FROM tbl

Grouping by multiple columns with equal priority in MySQL

I have a table of data, and I want to be able to output all the data that does not repeat the contents of two columns, an illustration:
Example table:
Column1 | Column2 | Column3
1 XX pop
2 YY yif
3 ZZ pop
4 PP pop
5 XX pop
6 YY yif
7 PP Hor
8 MM tre
9 PP pop
10 XX pop
11 MM pop
What I want to do here is output all rows where the values for both Columns 2 and 3 are not repeated, so you will see that Column1 == 1 and Column1 == 5 have the same values in both Column2 and Column3, so they only need to output where Column1 == 1 and not =5 (or =10).
I would like to set the query to output all rows, except where Column1 == 5,6,9,10 because these have both Column2 and Column3 repetition.
Intended output of query: (note: all three columns are required)
Column1 | Column2 | Column3
1 XX pop
2 YY yif
3 ZZ pop
4 PP pop
7 PP Hor
8 MM tre
11 MM pop
I have tried looking into Group By but this only appears to group by one column, or at least groups them from left to right so GROUP BY (Column2, Column3) would GROUP BY all values in Column2 and then values in Column3 rather than treat both columns equally.
I found one possible solution which was to concat the columns beforehand, such as
GROUP BY CONCAT(Column2, '_', Column3)
From Is it possible to GROUP BY multiple columns using MySQL? but this has been vaguely criticised (at least, as an answer to that question), but seems the closest code I've seen to do what I want to do.
So, how should I structure my GROUP BY clause to reach this outcome?
Is the GROUP BY CONCAT I have found a good way of approaching this?
GROUP BY on multiple columns is possible. Depending on the result you want, you have to apply extra GROUP functions to the rest of your data. In your case it looks like you want the first column1 index, and unique combinations of (column2,column3)
The following query should do the trick:
SELECT MIN(column1) AS column1,column2,column3
FROM table1
GROUP BY column2,column3
ORDER BY MIN(column1) ASC;
If you don't care about Column1 at all, you don't even need GROUP BY. Just use DISTINCT
SELECT DISTINCT Column2, Column3
FROM the_table
ORDER BY however_you_want
;
Otherwise, Norbert's answer is probably more fitting.

MySQL Query across multiple similar views

I'm trying to write a query that compounds many MySQL Views. The MySQL version I'm using is the latest that Amazon's AWS RDS service provides. These views look like:
View 1: "Count of AAA Events"
Col1: Timestamp
Col2: Count
View 2: "Count of BBB Events"
Col1: Timestamp
Col2: Count
I have a about 100 of these views.
I would like to have a query that shapes this data to look like this:
Col1: Timestamp
Col2: Count
Col3: Event Type
That means the data would look like:
2013-01-01T00:00:00Z 10 BBB
2013-01-01T00:00:00Z 10 AAA
2013-04-10T00:00:00Z 26 AAA
2013-04-10T00:05:00Z 28 AAA
The timestamps will NOT be unique, but the combination of Time + Event Type is unique.
I've tried a wide array of approaches, but nothing has given me quite what I want. Performance isn't an issue, as these are summary reports, not OLTP queries.
Any suggestions for a good way to approach this?
SELECT Col1, Col2, "AAA" AS Col3 FROM View1
UNION ALL
SELECT Col1, Col2, "BBB" AS Col3 FROM View2
UNION ALL
SELECT Col1, Col2, "CCC" AS Col3 FROM View3
UNION ALL
.
.
.
and so on.
With help from the folks above, the final results look like this:
Select * from
(
(SELECT PointInTime, (Col1+Col2+Col3) as Failures, "ApiName1" FROM Table1)
union all
(SELECT PointInTime, (Col1+Col2+Col3) as Failures, "ApiName2" FROM Table2)
order by PointInTime
) as X;
The use of the sub-query lets me shape the final column names should I need to.
That gives results that look like:
PointInTime FailedBuckets API
2013-01-01 0 ApiName1
2013-01-01 1 ApiName2
2013-01-02 0 ApiName1
2013-01-02 1 ApiName2

MySQL query (condition)

I want to achieve one thing though I'm not sure if it's possible.
So let's say I have a table with few columns, but only two of them are of interest to me right now. Example of table:
Column 1 | Column 2
blabla | blablahhhhh
wor154 | blablahhhhh
word123 | word12435564
something | some4565
What I want to achieve, is to select all fields where first 5 or more symbols of value of Column 2 don't match with first 5 or more symbols of value of Column 1. So I don't want to select rows where 5 or more symbols of value of Column 1 match 5 or more symbols of value of Column 2. In example, query should return only 2nd and 4th rows
So, is it possible and if it's, how it can be achieved. Thank you.
I'd go with a SUBSTRING():
SELECT col1 FROM table WHERE SUBSTRING(col1, 1, 5) <> SUBSTRING(col2, 1, 5);
You can use something similar to this:
select *
from table1
where substring(column1, 1, 5) != substring(column2, 1, 5)
See SQL Fiddle with Demo