Access 2010 Query across multiple fields - aggregate

I am an absolute Noob when it comes to Access 2010. I am trying to figure out what I believe is a common task.
I want to do a Query across multiple fields giving me a total. Let me give you an example:
I sell fruit, only 3 kinds and say my Table has an ID, Name, Item 1, Item 2, Item 3, and other unrelated fields.
An order could look like this:
ID1 Bill Smith Apples
ID2 John Jones Bananas Apples
ID3 Mary Cross Oranges Bananas Apples
I would want a Query to "Scan" (probably the wrong word) the Item 1 field, Item 2 field, and Item 3 field and return a Totals count as follows:
Apples 3
Bananas 2
Oranges 1
Notice that Apples, Bananas and Oranges can be in ANY Field, in ANY order...
Thank you for your Time and Expertise
Ray

The problem is your table structure, how many items can be in each order, three, four, five? Do you intend to add another column if someone orders six items?
They way to do this is keep orders in one table and the line items in another and link them
Table orders:
order_id
name
1
Bill Smith
2
John Jones
3
Mary Cross
Table orderItems:
item_id
order_id
item
1
1
Apples
2
2
Bananas
3
2
Apples
4
3
Bananas
5
3
Apples
6
3
Oranges
Then use a query which joins the two tables together:
select o.order_id,o.name,oi.item from orders o left join orderItems oi on o.order_id = oi.order_id
Will give an output of:
Order_ID
Name
Item
1
Bill Smith
Apples
2
John Jones
Apples
2
John Jones
Bananas
3
Mary Cross
Apples
3
Mary Cross
Bananas
3
Mary Cross
Oranges

Related

Number of Order From Customers

This seems like a simple question but I'm having trouble building my graph. I'm trying to get the number of customers who made 1 order, 2 orders, 3 orders etc..
Sample Data Source:
Customer ID| Order ID| Date Ordered
A 10 06/01/2019
A 11 06/02/2019
A 12 06/02/2019
B 15 06/05/2019
B 16 06/05/2019
B 17 06/05/2019
C 20 06/06/2019
C 21 06/06/2019
I can easily get the graph to show that Customer A made 3 Orders , Customer B made 3 Orders and Customer C made 2 orders.. etc.
What I'm trying to show is how many customer places a certain number of orders . So in our sample data. 1 Order = 0 , 2 Orders = 1, 3 Orders = 2. So in the X axis im trying to show (1 Order, 2 Orders , 3 Orders, 4 Orders.. etc )
I tried doing calculations such as IF COUNT([CustomerID]) > 2 then '1 order' but I can't seem to get it right. Any advice will be helpful. Thanks in advance
Maybe you can try using LOD expressions and create a new calculated field like this:
{INCLUDE [Customer ID]: COUNTD([Order ID])}
And then use that field to show that info.

Group by specific column in PostgreSQL

I trying to get a count of person depending on the org_id.
Let's say I have 10 people in my people coming in from different organization.
I want to count no of people working in separate with each record listed.
Please click here on SQL Fiddle link to get what exactly I am trying to do.
Postgres version 9.4
Below are my table records:
id person_name emp_id org_id
1 John Mackenzie TTT104 1
2 Raven Raid TTT105 1
3 Albert Pinto TTT106 2
4 Albert Pinto1 TTT119 2
5 Ram Raman TTT108 2
6 Huge Jackman TTT109 2
7 Peter Pan TTT107 2
8 Albert Pinto2 TTT106 2
RESULT EXPECTED:
id person_name emp_id count(org_id)
1 John Mackenzie TTT104 2
2 Raven Raid TTT105 2
3 Albert Pinto TTT106 6
4 Albert Pinto1 TTT119 6
5 Ram Raman TTT108 6
6 Huge Jackman TTT109 6
7 Peter Pan TTT107 6
8 Albert Pinto2 TTT106 6
As shown in the image I want my records to look in my velocity template:
While collecting results, you The solution you are looking for is the following:
SELECT org_id, count(*)
FROM person
GROUP BY org_id;
Basically with this query you are collecting the number of people working in each distinct org_id.
Result of the query is, then:
rg_id | count
-------------
1 | 2
2 | 6
Execute query as below to solve the issue:
SELECT p.person_name,
p.emp_id,
count(p.org_id) OVER w as org
FROM person p WINDOW w AS (PARTITION BY org_id);

Crystal Reports Rows in Group

I have a report grouped by Supplier. In the details section for this group, there are customer names with other fields of information. The problem is that a customer may be listed several times, but I only want one record to show per customer.
Supplier
John Doe 10/15 $25.00 Eggs
John Doe 10/15 $29.00 Milk
Susan Weva 10/12 $15.00 Corn
Susan Weva 10/18 $11.00 Bread
What I want is one complete row for John Doe and one for Susan Weva. Any idea as to how I can do this? I tried to suppress each field, but that did not seem to work.
There is one way (which i use in this situations) and it work.
So your data looks like this
John Doe 10/15 $25.00 Eggs
John Doe 10/15 $29.00 Milk
Susan Weva 10/12 $15.00 Corn
Susan Weva 10/18 $11.00 Bread
From what i have understand you want to have your output like
John Doe some columns
Susan Weva some columns
To show it only once per group put fields in group header or group footer. In your case all other columns are different and you should "summarize" those fields. For field price is easy, just do summarize by group and you have for each person amount. But dates and last columns makes a problem. So you should learn about using Cross-tab to solve this problem. If you need only sum of price, then put fields in group header or group footer and it will be show only once per group.
Hope it helps

Excel: how to generate the list of IDs after I select the items from a list?

I am thinking to generate a list of IDs after I select the items from a data sheet. But I don't know where to start. Can you give me some hints? Any help is appreciated!
Thanks!
Here is how my worksheet looks like. I have five columns, namely, ID, Category, Name, Sub Name, and Checkbox. Checkbox is now empty, because I don't know how to make one. But ideally, I want to create a check box for each item (each row), so I can choose the items I want. At the bottom of the worksheet, I want to create a button, called "Click to generate the selected list witht their IDs". Ideally, I can click it to get a list of IDs of the selected (checked) items from above.
Furthermore, I am thinking to create a fold-in Category and Name, so smaller items, such as Pink Lady and Royal Crisp can be folded as Apple. When I select Apple, automatically, I select both Pink Lady and Royal Crisp.
Are these requirements doable? Please help! Thanks in advance!
ID Category Name Sub Name Checkbox
1 Fruit Apple Pink Lady
2 Fruit Apple Royal Crisp
3 Fruit Banana Brazil
4 Fruit Banana Agentine
5 Fruit Grape
6 Fruit Orange
7 Fruit Peach
8 Vegetable Celery
9 Vegetable Carrot Baby Carrot
10 Vegetable Carrot Ordinary Carrot
11 Vegetable Cabbage
12 Vegetable Potato Idaho Potato
13 Vegetable Potato White Potato
14 Vegetable Tomato Cherry Tomato
15 Vegetable Tomato Ordinary Tomato
Click to generate the selected list witht their IDs

Crystal Reports grouping two tables based on the primary key of one table

I have 2 tables:
Product
fields are: prod_no (primary key), prod_name
Sales
fields are: sal_no, sal_date, cust, prod1 (foreign key i.e. prod_no), prod2 (foreign key i.e. prod_no), fst_qty, snd_qty
I want to sort my report based on prod_no.
Example:
Product
prod_no prod_name
1. printer
2. paper
3. cartridge
Sales
sal_no sal_date customer prod1 prod2 fst_qty snd_qty
1 5-sep-09 aaa 1 3 2 3
2 5-sep-09 bbb 2 3 1 1
3 5-sep-09 ccc 1 2 3 4
I want a report like this:
prod_no
1
sal_no sal_date customer qty
1 5-sep-09 aaa 2
3 5-sep-09 ccc 3
2
2 5-sep-09 bbb 1
3 5-sep-09 ccc 4
3
1 5-sep-09 aaa 3
2 5-sep-09 bbb 1
Book - Crystal reports 10: the complete reference By George Peck
Looks like a job for subreports to me, with Prod_No passed as a parameter.
You need to work on your grouping skills for this. I believe that if you simply create groupings for prod_no and then sal_no, and after placing the necessary fields in the proper group headers and details sections you should be able to display this info in the way that you want it.
Please see my answer on the below question for an example of a grouping similar to what you are looking for.
How to avoid the duplicate values?
Hope this helps and don't forget to mark an answer as the accepted answer and vote for answers that have helped. Thanks