I have a table defined in AX like follows:
I am trying to create an SSRS report using a query to create the DataSet and as Design - PrecisionDesign.
I got this until now:
with groupings :
I would like to visually replicate this query:
SELECT Country
, City
, FirstName
, SUM(AGE)
FROM TABLESSRSGROUPING
GROUP BY Country, City, FirstName
Resulting in:
You should only need to group once within the first Row Grouping.
In the Group Properties - group on [Country] then ADD [City] then ADD [Name]
Let me know if this helps
What value do you have in the sum field in the SSRS report?
Is it
Fields!.Age.Value
or
sum(Fields!.Age.Value)
Your report is diplaying the DETAIL for all records.
The Details group has the three lines to the left, indicating that it is showing all lines and NOT grouping like you want.
Change your Details to Group on FirstName and delete your FirstName group (select DELETE GROUP ONLY not the Related Rows and Columns)
On a different note, you're adding AGEs?
Related
I have a mySQL table with 100 rows and 6 columns namely ; full_name, name, score, city, gender, rating. I want the output as one column containing distinct city values (there are only 5 distinct cities initially & the user input value of his/her city will be added, namely; Delhi, Mumbai, Patna, Chennai ,Pune) and the second column having their respective avg score.
The database is linked to the python code which I am working on & use takes input which is stored in the above 6 columns. Then according to the user request, the output as analysis is showed as graphs using matplotlib. But I am really stuck at this part where I need to show a graph having X-VALUES as city names and Y-VALUES as respective avg score for that, I need to know the query to get such an output in mySQL where we get 2 columns storing the above.
How do I do it ?
SELECT city AS X,AVG(score) AS Y
FROM yourtable GROUP BY city
Is this, what you ment? Or if you want the result as one row, you add GROUP_CONCAT:
SELECT GROUP_CONCAT(X) AS gX,GROUP_CONCAT(Y) AS gY FROM
(SELECT city AS X,AVG(score) AS Y
FROM yourtable GROUP BY city) g
ok, redbull helps...
correct syntax :
select city, avg(score) from data group by city;
wrong syntax (what I was trying to do earlier) :
select data.distinct(city), data.avg(score) , check.check_city from data, (select name, distinct(city) as check_city from data) check where data.name = check.name and data.city in check.check_city;
Thanks Anyway !
I have a table that in one column has security companies in it, another column has the id of the parent company, and the last column has that security company's market value.
I am trying to calculate the parent company's market value by adding together the market values of the security companies with the same parent id, how do I accomplish this?
The table is called security and I want the new column to be called ParentSecMktValue.
I have tried using SELECT statements:
SELECT security.Parent_id, security.SecMktValue
FROM security
ORDER BY Parent_id ASC;
This produces a table of the parent id's and their market values but I am unsure how to combine the data from the different rows.
SELECT s.Parent_id, SUM(s.market_value) AS ParentSecMktValue
FROM security s
GROUP BY s.Parent_id
;
You can get the sum by using group by on parent_id and using sum function on market value
SELECT security.parent_id, SUM(security.SecMktValue)
FROM security GROUP BY parent_id
ORDER BY Parent_id ASC;
I want to get data from table in a single row for single county. Right now as shown in images it shows Different rows for Single county as Kalamazoo. It should show single with both records in single row.
I am using following query
SELECT County, Virus, SumOfPositiveTests
FROM StatewiseData
WHERE State = 'MICHIGAN'
I want the results to be shown as following
County Virus SUMOFPOSITIVETESTS
---------------------------------------------
Kalamazoo H3N2,H3N8 3
Total sum of both H3N2 and H3N8
use MYSQL GROUP_CONCAT
The following MySQL statement will return a list of comma(,) separated 'Virus's for each group of 'County' from the StatewiseData table
SELECT County,GROUP_CONCAT(Virus),sum(SumOfPositiveTests) FROM StatewiseData where State='MICHIGAN' group by County
Try this if you are using mysql:
SELECT country, GROUP_CONCAT(virus) _virus, SUM(SumofPositiveTests) as TotalPostitiveTest
FROM StatewiseData
WHERE Country = 'Kalamzoo'
GROUP BY Country
Please mind that this will not work with most databases, as they need you to to specify only the grouping field and aggregate functions of other fields in your query.
Here is the source
Try this. this would work on IBM DB2 and MySQL. what DB you are using
SELECT DISTINCT Country, Virus,SumOfPositiveTests FROM Customers where State='MICHIGAN' group by Country;
why are you using state in where condition? (please provide list of columns do you have in a column if i missed something)
if you are only selecting the country then it should be as simple as:
SELECT County,Virus,SumOfPositiveTests FROM StatewiseData where Country='Kalamzoo'
if you want to select summary or totals of single country then you you should use sum like:
SELECT country, SUM(SumofPositiveTests) as TotalPostitiveTest
FROM StatewiseData WHERE Country='Kalamzoo' GROUP BY Country
How to display all fields of a row based on 1 field that is distinct (i.e there should no duplicates for this field)
Suppose there's a table called Office_Roles with the fields and data as below
Name Department Designation
John Marketing Executive
John Sales Executive
John PR Executive
So i want the end result to display all the fields in a row but for just 1 John (distinct)
Output like -
John Marketing(or Sales) (or Pr) Executive
I was thinking of something like
select * from Office_Roles where name =(select distinct name from Office_Roles);
How do we do something like this correctly ? I also want to do a Order By and Limit the number of results per page on the end result...
You can't have a variable number of columns for a query. One thing you can do is to concatenate the values together:
select name, group_concat(Department) as departments,
group_concat(Designation) as designations
from Office_Roles o
group by name
This will not output exactly how you want , but see if it works for you. Just to give you an idea.
select name, group_concat(Department SEPARATOR ' or ') as departments,
Designation
from Office_Roles a
group by name,Designation
Yoy can play with SQL Fiddle here Demo
You are going to get 3 rows either way since there are 3 in the table that match, which rows are you trying to exclude and how is the query supposed to know what to NOT show?
I would just use GROUP BY
SELECT * FROM Office_Roles GROUP BY name;
easy.
Working with MS Access for the first time and coming across a few problems if someone could please point me in the right direction.
So I'm doing a mock database (so it looks silly) just to learn the ins and outs and need some help with DLookUp at the moment.
My database has two tables, with the following fields:
C_ID the PK in Courses and FK in Student
tblCourse: C_ID, Title, Subject
tblStudent: S_ID, C_ID, Name, EnrollDATE
As I said this is just for testing/learning. So what I want is to have a filter that gives me a list of C_ID's based on which EnrollDates are NULL.
so filter is:
Expr1: DLookUp("[tblStudent]![C_ID]","tblStudent","isNull([tblStudent]![EnrollDATE])")
I have also tried with the criteria being
[tblStudent]![EnrollDATE] = Null
Currently I get just blank fields returned. Any help is greatly appreciated, and please ask me to elaborate if my explanation is off.
Thank You!
The correct syntax looks like this:
DLookup("C_ID", "tblStudent", "EnrollDate is null")
You don't need to include the table name when you specify the columns
In Access, you check for Null by using xxx is null or xxx is not null
Note that DLookup only returns one value (if the criteria matches more than one row, the value is taken from any row), so you can't use it to get a list of C_IDs back.
EDIT:
What you actually want to do is select data from one table, and filter that based on data from the other table, correct?
Like, selecting all courses where at least one student has an empty EnrollDATE?
If yes, you don't need the DLookup at all, there are two different ways how to do that:
1) With a sub-select:
select *
from tblCourse
where C_ID in
(
select C_ID
from tblStudents
where EnrollDATE is null
)
2) By joining the tables:
select tblCourse.*
from tblCourse
inner join tblStudent on tblCourse.C_ID = tblStudent.C_ID
where tblStudent.EnrollDATE is null
This is SQL, so you need to switch to SQL View in your query in Access.