I want to simulate the pivot table.
how to sum the subtotal of the father field, like this
ID - SubID - SumOfSubID -- TotalbyID
1 --- A ------- 11 ------------------------ 95
1 --- B ------- 13 ------------------------ 95
1 --- C ------- 71 ------------------------ 95
2 --- T ------- 33 ------------------------ 55
2 --- H ------- 22 ------------------------ 55
how to calculate the TotalbyID like this (ex: ID = 1 then TotalByID = 11+13+71) ?
At the moment I'm using stacked query, but how can I do this with subquery or any method faster ?
It seems to me that you can either use linked queries, as you are, or Domain Aggregate functions such as DSum(). I expect what you have is already the faster of the two anyway.
@Rabbit: Stacked query is the query used inside another query, sound like traped query. let me see, UNION can combine 2 query and I don't have to play a query inside another ? ==
@NeoPa: Dsum() and his relative are whom I want avoid the most,
they slow me down too much haha
I'll try rabbit's suggestion, union, but I have never use UNION before lol, let see if this can be done.
HVSummer:
@NeoPa: Dsum() and his relative are whom I want avoid the most
Very wise. Note I was not suggesting you try that as I assumed what you had was already better.
HVSummer:
I'll try rabbit's suggestion, union, but I have never use UNION before lol, let see if this can be done.
If you haven't played with UNION queries before then certainly go off and explore them. They can be very powerful and add flexibility.
In this case, I don't see where the benefit would come from above and beyond the use of subqueries (Subqueries in SQL), which is what I assume you started with.
Having said that, Rabbit is certainly extremely clever, and particularly so when it comes to SQL, so I expect there's something I've missed.
well, UNION must have the same select field's number, and it work like
append query, append bonus query into a query ==
if I use subquery, how to do it :-? (usually stacked query faster than subquery, but I'll try once, i won't let this simple task take away 2 slot queries from me ==)
my code uptill now (subquery method):
Expand|Select|Wrap|Line Numbers
SELECT A.ID, A.SUBID, SUM(A.VOLUME) AS SUMOFSUBID, B.TOTALBYID
FROM A INNER JOIN
(SELECT ID, SUM(A.VOLUME) AS TOTALBYID FROM A) AS B ON A.ID = B.ID
Note the differentiation of "stacked" queries vs. subquery.
In Access the "stacked query" is stored query that is referred to via a second query, third, etc...
The subquery we all know and love is where the SQL is created within the primary sql.
I often start by building the individual queries for troubleshooting each piece, stacking as I go, and then combine for use in code... or just to tidy things up.
The issue I have with this is that stacking queries is a favorite SQL-Injection method used against RDMS (or any DBE) that is capable of running async multiple queries... or, well, so, I've been told...
hvsummer, that's what my suggestion was in post #2. Except your sample results didn't match what your query would create, which is why I withdrew my suggestion and NeoPa made his suggestion.
But also, this kind of stuff is handled better at the report level because it allows for better formatting options.
yes, unlucky I'm the rest 1%..
coz I calculate everything in access, can do this ezier in excel, but I don't want setup too much steps. I need subtotal or grantotal as a part of fomular sothat reporting option does not help, I have to generate result (fomular relative to subtotal like Volum-weighted) with query first.
Sometime people have to do that too, so I think we should findout their need to fullfill it rather than give "our best direction" every question.
The "best direction" should always take into account the user's need. If they need it in query form and have a valid reason, then I would give them the 1% solution. If they are unclear or don't need it calculated within the query, then the 99% solution is the answer I would give them.
Just to be clear, it's the use case rather than the user that determines what is appropriate for any given scenario. It's possible for a designer to provide a solution that doesn't match the requirements very well. There are always many ways to provide a solution.
Nevertheless, there are sometimes cases when the 1% is needed. That will be clear because the 99% won't work for some reason. It won't be connected in any way with who the developer is. If your choice is to go with the 1% regardless of the use case then that simply means you're not doing it the most appropriate way.
We will always suggest, to the best of our ability, the most appropriate way. We see that as our responsibility. What you do from there is your own lookout. We see that as yours.
yea, I know what is the right direction for most of people, and you guy help me much when resolved my funny problem.
the reason i don't use report or form or anything else other than query is that I'm using Access as back-end, excel as front-end, I pull all data from access and show up in excel.
and the real reason, I'm lazy to calculate with excel :p
just want to calculate everything within query then pull out the result. It's hard, but it's worth for me.
Indeed. Depending on various parameters of what you need the spreadsheet for and how you're using it, that could make it one of the 1%. Essentially that's for you to decide anyway - not if it's a 1% but rather what you want to do.
As long as we've given the advice we're happy with then it's fine to explore other options.
i have an *access database + ASP newsletter* that is working fine and
it sends newsletter to ALL the email addresses in the DB.
i want to send this newsletter to only a select group (like people...
Hi,
I have a table which logs for sake of argument page hits:
id, timestamp, ipaddress
Now, I'm running a query to get an activity report and I want to group
together all the hits from a...
The following query will give me the top ten states with the most callers.
SELECT TOP 10 Count(Callers.CallerID) AS CountOfCallerID, Callers.State
FROM Callers
GROUP BY Callers.State
ORDER BY...
Is a SELECT TOP query allowed in filtering rows from a
datatable? If it is not, is there any other easy way to
filter a given number of rows from a datatable? Thanks a
lot for your help.
I've got a a datasheet subform that gets its data from a SELECT DISTINCT query. The data is not editable. When I remove the DISTINCT qualifier from the query, the data is editable, but of course I...
Hello,
I am trying to create a running subtotal in a query and then graph the
running subtotal for each city group. The data looks like this in the
table (for illustration):
My City My...
Hi all,
I have a query that uses a subquery to subtotal one of its fields.
This part is working fine. The twist is that when I encounter certain
values, I want to reset the subtotal to zero and...
I seem to have a few duplicates entries in a very large database.
My database has two identical tables. One is written to on a regular basis (every few seconds) and the other is used for queries,...
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...