I have a problem to produce a SSRS report that is like this:
This is how my output from stored procedure looks like:
Company Code | Company Name | Product Code | Product Name
ICE001 | Nestle | ICE001a | Drumstick Chocolate
ICE001 | Nestle | ICE001b | Drumstick KitKat
ICE001 | Nestle | ICE001c | Drumstick Chocolate
ICE002 | Walls | ICE002a | Cornetto Chocolate
ICE002 | Walls | ICE002b | Cornetto Latte
ICE002 | Walls | ICE002c | Cornetto La Liga
So how can I achieve this report structure in SSRS with the current stored procedure? Is it achievable?
Actually, yes you can. These are the steps:
Drag a table into the SSRS.
Make it 2 columns and 1 row.
On the first column, select the field you want as the sub data which in this case, Product Code.
In 2nd column, put in Product Name.
Now for the main data. Right click on the first column, select:
Insert Row > Outside Group - Above
Put the main data field which is Company Code at the first row, first column.
Put the Company Name expression at the second column, first row of the table.
Design as your preferred and generate your report :)
Doubt it. But if you adjust your dataset as below and use a table report it is.
select distinct code,company from icecream
union
select productcode,productname from icecream
Related
I have a section table and class Table
class table is designed in this way
(id,class_name,section_id)
one class has many sections like
--------------------------------------------
| SN | ClassName | Section_id |
--------------------------------------------
| 1 | ClassOne | 1 |
| 2 | ClassOne | 2 |
| 3 | ClassOne | 3 |
| 4 | ClassOne | 4 |
--------------------------------------------
Now i want to groupBy Only ClassName and display all the sections of that class
$data['classes'] = SectionClass::groupBy('class_name')->paginate(10);
i have groupby like this but it only gives me one section id
Try this way...
$things = SectionClass::paginate(10);
$data['classes']= $things->groupBy('class_name');
You are getting just one row because that is what GROUP BY does, groups a set of rows into a set of summary rows and returns one row for each group. In standard SQL, a query that includes a GROUP BY clause cannot refer to nonaggregated columns in the select list that are not named in the GROUP BY clause. For example, in SQL Server if you try the next clause
SELECT * FROM [Class] GROUP BY [ClassName]
You'll get the next error
"Column 'SN' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause"
Think about it, you are grouping by ClassName, and following your sample data, this will return just one row. Your SELECT clause includes column ClassName, which is easy to get because is the same in every single row, but when you are selecting another, which one should be return if only one has to be selected?
Now, things change a little bit in MySQL. MySQL extends the standard SQL use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. This means that the preceding query is legal in MySQL. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are nondeterministic. You can find a complete explanation about this topic here https://dev.mysql.com/doc/refman/5.6/en/group-by-handling.html
If you are expecting a result in one row, you can use GROUP_CONCAT() function to get something like
--------------------------------
| ClassName | Sections |
--------------------------------
| ClassOne | 1,2,3,4 |
--------------------------------
Your query must be something like:
select `ClassName`, group_concat(Section_id) from `class` group by `ClassName`
You can get this with a raw query in laravel or its up to you to find a way to get the same result using query builder ;)
I've read through similar questions and they don't seem to quite fit my issue or they're in a different environment.
I'm working in MS-Access 2016.
I have a customer complaints report which has fields: year, month, count([complaint #]), complaint_desc.
(complaint # is the literal ID number we assign to each complaint entered into the table)
I grouped the report by year and month and then grouped by complaint_desc and for each desc did a count of complaint number, and then did a count of complaint # to add up total complaints for the month and stuck it in the month footer which gives a result of something like this:
2020 03 <= (this is the month group header)
complaint desc | count of complaints/desc
---------------------------------------------
electrical | 2 {This section is
cosmetic | 6 {in the Complaint_desc
mechanical | 1 {group footer
---------------------------------------------
9 <= (this is month group footer)
repeating the group for each month
This is all good. What I want to do is to sort the records within the complaint desc group in descending order of count(complaint#) so that it looks like:
2020 03
complaint desc | count of complaints/category
---------------------------------------------
cosmetic | 6
electrical | 2
mechanical | 1
---------------------------------------------
9
However nothing I do seems to work, the desc group's built-in sort "a on top" overrides sorting in the query. adding a sort by complaint# is ignored also. I tried to add a sort by count(complaint#) and access told me I can't have an aggregate function in an order by (but I think it would have been overridden anyway). I also tried to group by count(complaint#) also shot down as aggregate in a group by. Tried moving complaint_desc and count(complaint#) to the complaint# group header and it screwed up the total count in the month footer and also split up the complaint desc's defeating it's original purpose...
I really didn't think this change was going to be a big deal, but a solution has evaded me for a while now. I've read similar questions and tried to follow examples but they didn't lead to my intended result.
Any Idea?
I figured it out! Thank you to #UnhandledException who got me thinking on the right track.
So here's what I did:
The original query the report was based on contained the following:
Design mode:
Field | Year | Month | Complaint_Desc | Complaint# |
Total | Group By | Group By | Group By | Group By |
Sort | | | | |
or in SQL:
SELECT Year, Month, [tbl Failure Mode].[Code description], [Complaint Data Table].[Complaint #]
FROM [tbl Failure Mode] RIGHT JOIN [Complaint Data Table] ON [tbl Failure Mode].[ID code] = [Complaint Data Table].[Failure Mode]
GROUP BY Year, Month, [tbl Failure Mode].[Code description], [Complaint Data Table].[Complaint #];
And then I was using the report's group and sort functions to make it show how I wanted except for the hiccup I mentioned.
I made another query based upon that query:
Design mode:
Field | Year | Month | Complaint_Desc | Complaint# |
Total | Group By | Group By | Group By | Count |
Sort | Descending | Descending | | Descending |
or in SQL:
SELECT [qry FailureMode].Year, [qry FailureMode].Month, [qry FailureMode].[Complaint_description], Count([qry FailureMode].[Complaint #]) AS [CountOfComplaint #], [qry FailureMode].Complaint
FROM [qry FailureMode]
GROUP BY [qry FailureMode].Year, [qry FailureMode].Month, [qry FailureMode].[Code description], [qry FailureMode].Complaint
ORDER BY [qry FailureMode].Year DESC , [qry FailureMode].Month DESC , Count([qry FailureMode].[Complaint #]) DESC;
Then I changed the report structure:
I eliminated the Complaint_Desc group, moved complaint_desc and CountofComplaint# (which is now not a function but it's own calculated field from my new query) to the DETAIL section of the report. Then I deleted my 2nd count(complaint#) that was in the month footer as a total for each month and replaced it with the "AccessTotalsCountOfComplaint #" which is =Sum([CountOfComplaint #]) which I had access auto-create by right-clicking on the CountofComplaint_Desc in details scrolling to "Total" and clicking on "Sum". (I deleted the extra AccessTotalsCountOfComplaint#'s that were outside of the Month Group Footer that I needed it for...)
Et Voila
I hope this helps someone else, and thank you again to Unhandled Exception who pointed me in the right direction.
I am trying to set up a query in a Google sheet that shows a column of data based on the header and then sorts the numerical values in the column and keeps the referencing row. https://docs.google.com/spreadsheets/d/14kQxqck_NbJ195IF3ALOgFIR23K5nKqXRuk47nvUDoo/edit?usp=sharing
I have read through the wiki help on Google Sheets for query and I'm lost of what to do to get the results I want.
=query(TeamNeeds!B1:O39,"where C='"&C1&"'",-1) is what I have currently and I know it isn't close to what I need.
I would like to use the dropdown in C1 and have it show the associated column on the next sheet over and then sort the data with updating referencing titles (FLYING, GROUND, ROCK, etc.)
+------------+
| Pidgey |
+--------+---+
| FIRE | 3 |
+--------+---+
| GROUND | 2 |
+--------+---+
| ICE | 0 |
+--------+---+
=QUERY({TeamNeeds!A1:A, TRANSPOSE(QUERY(TRANSPOSE(TeamNeeds!B1:AC),
"where Col1 = '"&C1&"'", 0))},
"order by Col2 Desc", 1)
=QUERY(QUERY({TeamNeeds!A1:A, TRANSPOSE(QUERY(TRANSPOSE(TeamNeeds!B1:AC),
"where Col1 = '"&C1&"'", 0))},
"order by Col2 Desc", 1),
"offset 1", 0)
I've a working custom formula put in the data validation box in column A in a Google spreadsheet to disallow entering duplicates in the same column A.
=countif($A$3:$A$1677,A3)<=1
Now i have another column, column B, and i want the above formula to be moved in column B from column A editing it in such a way that it offers the following :
+---+------------+-------------+
| | A | B | <-- the custom formula to be kept in column B only (in the data validation box).
+---+------------+-------------+
| 1 | John | MySQL | <-- if this row/data is already existing, then
| 2 | John | Oracle | <-- this entry is allowed (bcoz the data in this row do not match with data in the above row (considering both columns), and
| 3 | Viv | MySQL | <-- this entry is also allowed (bcoz the data in this row also do not match with data in the above two rows (considering both columns), and
| 4 | Al | SQL | <-- this entry is also allowed (bcoz the data in this row also do not match with data in the above three rows (considering both columns), but,
| 5 | Viv | MySQL | <-- this entry is NOT allowed (bcoz the data in this row entirely match with data in one of the above rows - row no. 3 (considering both columns).
+---+------------+-------------+
I have modified the aforementioned formula a little as below :
=countif($A$3:$B$1677,B3)<=1
But it does not fulfill the 2nd condition (Viv, MySQL) stated above.
Try this:
=COUNTIF(ARRAYFORMULA($A$3:$A$1677&$B$3:$B$1677),A3&B3)<=1
Instead of checking each column separately, you just join the values together and check to see if more that one of joined string exists!
Hope that helps!
If I use something like a SERIAL (which is a random number) for my table's primary key, how can I select a numbered row from my table? In MySQL, I just use the auto incremented ID to select a specific row, but not sure how to approach the problem with an arbitrary numbering sequence.
For reference, here is the table I'm working with:
+--------------------+------+-------+
| id | name | score |
+--------------------+------+-------+
| 235451721728983041 | ABC | 1000 |
| 235451721729015809 | EDF | 1100 |
| 235451721729048577 | GHI | 1200 |
| 235451721729081345 | JKL | 900 |
+--------------------+------+-------+
Using the LIMIT and OFFSET clauses will return the nth row. For example SELECT * FROM tbl ORDER BY col1 LIMIT 1 OFFSET 9 returns the 10th row.
Note that it’s important to include the ORDER BY clause here because you care about the order of the results (if you don’t include ORDER BY, it’s possible that the results are arbitrarily ordered).
If you care about the order in which things were inserted, you could ORDER BY the SERIAL column (id in your case), though it’s not always the case because transaction contention and other things could cause the generated SERIAL values to not be strictly ordered.