473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Basic SQL Questions

5
Assuming a recordsource [tblSales] with fields [Week]; [Branch] & [Sales], you could try :
Expand|Select|Wrap|Line Numbers
  1. SELECT S1.Week, S1.Branch, S1.Sales, Count(S2.Week) + 1 AS [Ranking]
  2. FROM [tblSales] AS [S1] LEFT JOIN [tblSales] AS [S2]
  3.   ON tblSales.Week = tblSales2.Week
  4.  AND tblSales.Sales < tblSales2.Sales
  5. GROUP BY S1.Week, S1.Branch
  6. ORDER BY S1.Week, S1.Branch
Hello.
I´m a newer newbie to Access. (and SQL)
What is S1 and S2? Are these tables?
You also write about tblSales2?
Are these 3(?) tables to be created before the execution of this query?
Nov 19 '07 #1
5 2434
cargo
5
This will be faster:
Expand|Select|Wrap|Line Numbers
  1. SELECT *, ((SELECT Count(*) FROM qryWeeklySales WHERE Branch = x.Branch AND Sales > x.Sales;)+1) AS Rank
  2. FROM qryWeeklySales AS x;
  3.  
You need to use greater than if you're trying to rank by descending sales.
Hello,
what is the meaning of x? I guess
[tblSales] with fields [Week]; [Branch] & [Sales] ?

As I understand it´s assumed there already is a query called
qryWeekSales - how would that look like?
Do you mean it´s a query that creates a table (tblSales) that look like this
Week Branch Sales
1st AAA 10
1st BBB 15
2nd AAA 5
2nd BBB 10
2nd CCC 3

Thank you!
Nov 19 '07 #2
NeoPa
32,556 Expert Mod 16PB
I'll try to answer your questions but please don't use someone else's thread to ask your own questions in future. This is called thread hi-jacking and is considered bad etiquette (as well as being against the rules of this site).
This thread has been split away from How to rank a query in MS Access?.
Before I can start though there is some work I still need to do to tidy up this situation.

ADMIN.
Nov 19 '07 #3
NeoPa
32,556 Expert Mod 16PB
Hello.
I´m a newer newbie to Access. (and SQL)
What is S1 and S2? Are these tables?
You also write about tblSales2?
Are these 3(?) tables to be created before the execution of this query?
Some good questions. Good because they drew my attention to some bugs (shame) in my posted code. The code is now fixed (you can follow the link to see the new version).

Anyway, to your questions.
S1 & S2 are SQL Aliases.
tblSales2 was a mistake and should have been S2.
In a query such as this, the same table needs to be included twice so at least one of them MUST have an alias so SQL knows which is which. Aliases can also be used for other reasons and, as in this case, they can make more complicated SQL much more readable.
Nov 19 '07 #4
cargo
5
Anyway, to your questions.

S1 & S2 are SQL Aliases.
tblSales2 was a mistake and should have been S2.
In a query such as this, the same table needs to be included twice so at least one of them MUST have an alias so SQL knows which is which. Aliases can also be used for other reasons and, as in this case, they can make more complicated SQL much more readable.

Thank you very much for your help!
/cargo
Nov 25 '07 #5
NeoPa
32,556 Expert Mod 16PB
No problems. It's always good to get some straightforward and fundamental questions that can be answered as fact rather than as opinions or style which can complicate matters. There are certainly others out there who need this question answered too :)
Nov 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jorge | last post by:
Hi, I am new in .NET and I have some basic questions. 1 - How can I control a object from another form ? I need to change a checkbox state from another form. What's the best way to do it ? 2...
1
by: quincy451 | last post by:
Ok, some basic questions. I want to create a website with a table of data and a couple buttons that might take certain actions like bring up another table. I also want to present a form and have...
7
by: asfwa | last post by:
I'm new to C++ and I have some basic questions. I have written an app that does some network stuff in a worker thread. The thread function requests something from the server, gets it and creates...
4
by: Ramesh | last post by:
hi, Let me ask some basic questions. Can anybody explain me about the following questions: 1. When we have to create sn key? Whenever we compiled Component we have to create or it is a one time...
3
by: Jim H | last post by:
If there is a site someone can point me to that answers such basic questions, rather than taking up support's time posting answers, please let me know. I've developed C# .NET, unmanaged C++, and...
2
by: Water Cooler v2 | last post by:
I've not touched SQL server programming since 1999. I have very little memory of it and need some clarifications on some basic questions that I could even use a book for. Until I get myself a good...
4
by: Schüle Daniel | last post by:
Hello, first question In : cmp("ABC",) Out: 1 against what part of the list is the string "ABC" compared? second question
14
by: abctech | last post by:
Helo experts, I'm working on my first ever web application and I have some basic questions related to servlets if I may, I have 5-6 Java statements and preparedstatements in my servlet to...
6
by: simplicity | last post by:
I have some basic questions about alert() and confirm(): (1) Is it possible to customize the labels in the buttons, eg. put "Yes" instead of "OK"? (2) Is there a control over the text in the...
4
nemisis
by: nemisis | last post by:
Hi, I would like to know some answers of some basic questions. I am working on linux 1)What are the advantages/disadvantages of commands at the console promp compared to using GUI programs? 2)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
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...
0
Oralloy
by: Oralloy | last post by:
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.