Jaymond Flurrie
Well-known Member
- Joined
- Sep 22, 2008
- Messages
- 921
- Office Version
- 365
- Platform
- Windows
I have a working SQL query:
But how do I turn this to TOP n query? Ie. Let's says these 10, 11, 12... 89 are the sums that this query results. How do I select the columns where this sum is in Top 40 of those sums?
I'm pretty sure the answer should include that query mentioned above as a subquery and I'd guess it should treat that one above with "AS" and probably also somehow "IN", but I'm not sure what the actual query-line should be.
You can also simplify your answer quite a lot, take for example a "TOP 2" and that working SQL query from above as, say,
just to keep it simple.
I would imagine it goes something like
, but please help me to complete this one.
Code:
SELECT SUM(a10a), SUM(a11a), SUM(a12a), SUM(a13a), SUM(a14a), SUM(a15a), SUM(a16a), SUM(a17a), SUM(a19a), SUM(a20a), SUM(a21a), SUM(a22a), SUM(a23a), SUM(a24a), SUM(a25a), SUM(a26a), SUM(a30a), SUM(a31a), SUM(a32a), SUM(a33a), SUM(a34a), SUM(a35a), SUM(a36a), SUM(a37a), SUM(a38a), SUM(a39a), SUM(a40a), SUM(a41a), SUM(a42a), SUM(a43a), SUM(a44a), SUM(a45a), SUM(a48a), SUM(a49a), SUM(a50a), SUM(a53a), SUM(a54a), SUM(a59a), SUM(a60a), SUM(a61a), SUM(a62a), SUM(a63a), SUM(a64a), SUM(a65a), SUM(a66a), SUM(a67a), SUM(a68a), SUM(a69a), SUM(a70a), SUM(a71a), SUM(a72a), SUM(a73a), SUM(a74a), SUM(a75a), SUM(a76a), SUM(a77a), SUM(a78a), SUM(a79a), SUM(a80a), SUM(a82a), SUM(a83a), SUM(a84a), SUM(a85a), SUM(a86a), SUM(a87a), SUM(a88a), SUM(a89a) FROM [Ostoaineisto$];
But how do I turn this to TOP n query? Ie. Let's says these 10, 11, 12... 89 are the sums that this query results. How do I select the columns where this sum is in Top 40 of those sums?
I'm pretty sure the answer should include that query mentioned above as a subquery and I'd guess it should treat that one above with "AS" and probably also somehow "IN", but I'm not sure what the actual query-line should be.
You can also simplify your answer quite a lot, take for example a "TOP 2" and that working SQL query from above as, say,
Code:
SELECT SUM(a10a), SUM(a11a), SUM(a12a) FROM [Ostoaineisto$];
I would imagine it goes something like
Code:
SELECT TOP 40 FROM (SELECT SUM(a10a), SUM(a11a), SUM(a12a) FROM [Ostoaineisto$]);