![]() | |
#21
| |||
| |||
|
|
Question is: You have a single customer (identified by the customer id) and want to know at which place (perhaps this is the better word ?) it is by the specified ORDER BY. |
|
Since I do not store the place, I have to generate it every time I want this information by numbering the rows manually and then display the number which has the row with the correct customer id |
#22
| |||
| |||
|
|
Because it is nice to have the information where you are to a given ORDER BY and do not need to see the complete overview and have to look where you are. it is not about if this is really usefull or not, it is about if there is a good way to achieve this. |
#23
| |||
| |||
|
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 08/02/10 13:51, Doug Miller wrote: In article <hkov40$tnc$00$1 (AT) news (DOT) t-online.com>, =?ISO-8859-1?Q?Johannes_Ke=DFler?= <mail (AT) bananas-playground (DOT) net> wrote: Sorry if this is not as clear as it should be. here is an example customerid|name|price|points|sell - --------------------------------- 1|name1|10|22|1 2|name2|3|1|25 3|name3|15|84|23 4|name4|122|81|22 SELECT * FROM table ORDER BY price DESC result would be: customerid|name|price|points|sell - --------------------------------- 4|name4|122|81|22 3|name3|15|84|23 1|name1|10|22|1 2|name2|3|1|25 Now I want to know where in the list or at what possition a specific customer is. If I sort by price, customer 3 is at place 2. If I sort by points it would be at place 1. But right now there is no such information at which possition the customer is, I got this only by numbering the rows manually as described as my previous reply. Now the problem is that everytime I want to get a possiton I need to query the whole table with a different ORDER BY. And then number the rows manually. If the table has 10000 rows you have to number 10000 rows. And you have the data from 10000 rows. Image if the customer is at possition 3 you could only number until you reach this specific customer AND do not have to number all the 10000 rows, just to find out that the customer is a row 3. numbering all the other 9997 rows is useless and a wast of data which is pulled from the table. So my question is if I can create a query which just does this without getting all the data. I hope it is more clear now. But english is not my primary language. Yes, *that* much is clear. What is still unclear is why you think it is important to know what position that customer is in the table. see my reply to Captain Paralytic |
#24
| |||
| |||
|
|
On 8 Feb, 13:16, Johannes Keßler <m... (AT) bananas-playground (DOT) net> wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 08/02/10 13:49, Captain Paralytic wrote: On 8 Feb, 12:12, Johannes Keßler <m... (AT) bananas-playground (DOT) net> wrote: On 08/02/10 12:55, Captain Paralytic wrote: On 8 Feb, 10:12, Johannes Ke ler <m... (AT) bananas-playground (DOT) net> wrote: On 08/02/10 11:08, nemaC wrote: Is there a way I need only select the rows until the customerid ? eg. SELECT * FROM table UNTIL customerId = 22 ORDER BY price DESC with that I do not need to get all the data from the table. SELECT <field you need> FROM table WHERE custumerId=22; ?? No. I get the possition from counting the whole result table manually eg. $i=1; foreach($result as $entry) { $newArray[$entry['customerId']] = $i; $i++; } The possition is not stored in the database, and changes everytime you alter the "order by" regards, johannes ke ler I really don't understand what you are after. As you point out, there is no such thing as a "position" of a row in a table. Maybe if you told us what you ultimately want to achieve by this? Sorry if this is not as clear as it should be. here is an example customerid|name|price|points|sell --------------------------------- 1|name1|10|22|1 2|name2|3|1|25 3|name3|15|84|23 4|name4|122|81|22 SELECT * FROM table ORDER BY price DESC result would be: customerid|name|price|points|sell --------------------------------- 4|name4|122|81|22 3|name3|15|84|23 1|name1|10|22|1 2|name2|3|1|25 Now I want to know where in the list or at what possition a specific customer is. If I sort by price, customer 3 is at place 2. If I sort by points it would be at place 1. But right now there is no such information at which possition the customer is, I got this only by numbering the rows manually as described as my previous reply. Now the problem is that everytime I want to get a possiton I need to query the whole table with a different ORDER BY. And then number the rows manually. If the table has 10000 rows you have to number 10000 rows. And you have the data from 10000 rows. Image if the customer is at possition 3 you could only number until you reach this specific customer AND do not have to number all the 10000 rows, just to find out that the customer is a row 3. numbering all the other 9997 rows is useless and a wast of data which is pulled from the table. So my question is if I can create a query which just does this without getting all the data. I hope it is more clear now. But english is not my primary language. regards, johannes ke ler You still haven't answered my question. I asked "what you ultimately want to achieve by this?". By that I mean please explain WHY you need this information? What good is it intended to do you? What process is this supposed to achieve? It feels like you have a faulty design somewhere. If you explain what you ultimately want to achieve, we might be able to help correct it. Question is: You have a single customer (identified by the customer id) and want to know at which place (perhaps this is the better word ?) it is by the specified ORDER BY. Since I do not store the place, I have to generate it every time I want this information by numbering the rows manually and then display the number which has the row with the correct customer id -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iEYEARECAAYFAktwDsoACgkQE++2Zdc7EtdjqwCfX8DlsHWBeK 3RYVPV+L6DKJtQ W5wAoI1vjwMmMWffCClr8g8K3PohXhoM =3V4n -----END PGP SIGNATURE----- I am near to giving up on you in this thread. I and others keep asking you why you think you need this particular piece of information and all you keep repeating is that you want to know the place. One more chance. WHY DO YOU THINK YOU NEED THIS INFORMATION? WHAT GOOD IS IT INTENDED TO DO YOU? WHAT PROCESS IS THIS INTENDED TO SUPPORT? |
#25
| |||
| |||
|
|
Captain Paralytic wrote: On 8 Feb, 13:16, Johannes Keßler <m... (AT) bananas-playground (DOT) net> wrote: On 08/02/10 13:49, Captain Paralytic wrote: On 8 Feb, 12:12, Johannes Keßler <m... (AT) bananas-playground (DOT) net> wrote: On 08/02/10 12:55, Captain Paralytic wrote: On 8 Feb, 10:12, Johannes Ke ler <m... (AT) bananas-playground (DOT) net wrote: On 08/02/10 11:08, nemaC wrote: Is there a way I need only select the rows until the customerid ? eg. SELECT * FROM table UNTIL customerId = 22 ORDER BY price DESC with that I do not need to get all the data from the table. SELECT <field you need> FROM table WHERE custumerId=22; ?? No. I get the possition from counting the whole result table manually eg. $i=1; foreach($result as $entry) { $newArray[$entry['customerId']] = $i; $i++; } The possition is not stored in the database, and changes everytime you alter the "order by" regards, johannes ke ler I really don't understand what you are after. As you point out, there is no such thing as a "position" of a row in a table. Maybe if you told us what you ultimately want to achieve by this? Sorry if this is not as clear as it should be. here is an example customerid|name|price|points|sell --------------------------------- 1|name1|10|22|1 2|name2|3|1|25 3|name3|15|84|23 4|name4|122|81|22 SELECT * FROM table ORDER BY price DESC result would be: customerid|name|price|points|sell --------------------------------- 4|name4|122|81|22 3|name3|15|84|23 1|name1|10|22|1 2|name2|3|1|25 Now I want to know where in the list or at what possition a specific customer is. If I sort by price, customer 3 is at place 2. If I sort by points it would be at place 1. But right now there is no such information at which possition the customer is, I got this only by numbering the rows manually as described as my previous reply. Now the problem is that everytime I want to get a possiton I need to query the whole table with a different ORDER BY. And then number the rows manually. If the table has 10000 rows you have to number 10000 rows. And you have the data from 10000 rows. Image if the customer is at possition 3 you could only number until you reach this specific customer AND do not have to number all the 10000 rows, just to find out that the customer is a row 3. numbering all the other 9997 rows is useless and a wast of data which is pulled from the table. So my question is if I can create a query which just does this without getting all the data. I hope it is more clear now. But english is not my primary language. regards, johannes ke ler You still haven't answered my question. I asked "what you ultimately want to achieve by this?". By that I mean please explain WHY you need this information? What good is it intended to do you? What process is this supposed to achieve? It feels like you have a faulty design somewhere. If you explain what you ultimately want to achieve, we might be able to help correct it. Question is: You have a single customer (identified by the customer id) and want to know at which place (perhaps this is the better word ?) it is by the specified ORDER BY. Since I do not store the place, I have to generate it every time I want this information by numbering the rows manually and then display the number which has the row with the correct customer id I am near to giving up on you in this thread. I and others keep asking you why you think you need this particular piece of information and all you keep repeating is that you want to know the place. One more chance. WHY DO YOU THINK YOU NEED THIS INFORMATION? WHAT GOOD IS IT INTENDED TO DO YOU? WHAT PROCESS IS THIS INTENDED TO SUPPORT? I can think of a lot of reasons why this would be good - for instance, if the table holds an account balance, where does that customer rank in the list? Accounting would like to know that. Or maybe the table (more probably a view) holds the total sales. Marketing would like to know where that customer ranks in sales. A lot of reasons why one would want rankings. |
#26
| |||
| |||
|
|
In article <hkp2tr$rc1$03$2 (AT) news (DOT) t-online.com>, =?UTF-8?B?Sm9oYW5uZXMgS2XDn2xlcg==?= <mail (AT) bananas-playground (DOT) net> wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 08/02/10 13:51, Doug Miller wrote: In article <hkov40$tnc$00$1 (AT) news (DOT) t-online.com>, =?ISO-8859-1?Q?Johannes_Ke=DFler?= <mail (AT) bananas-playground (DOT) net> wrote: Sorry if this is not as clear as it should be. here is an example customerid|name|price|points|sell - --------------------------------- 1|name1|10|22|1 2|name2|3|1|25 3|name3|15|84|23 4|name4|122|81|22 SELECT * FROM table ORDER BY price DESC result would be: customerid|name|price|points|sell - --------------------------------- 4|name4|122|81|22 3|name3|15|84|23 1|name1|10|22|1 2|name2|3|1|25 Now I want to know where in the list or at what possition a specific customer is. If I sort by price, customer 3 is at place 2. If I sort by points it would be at place 1. But right now there is no such information at which possition the customer is, I got this only by numbering the rows manually as described as my previous reply. Now the problem is that everytime I want to get a possiton I need to query the whole table with a different ORDER BY. And then number the rows manually. If the table has 10000 rows you have to number 10000 rows. And you have the data from 10000 rows. Image if the customer is at possition 3 you could only number until you reach this specific customer AND do not have to number all the 10000 rows, just to find out that the customer is a row 3. numbering all the other 9997 rows is useless and a wast of data which is pulled from the table. So my question is if I can create a query which just does this without getting all the data. I hope it is more clear now. But english is not my primary language. Yes, *that* much is clear. What is still unclear is why you think it is important to know what position that customer is in the table. see my reply to Captain Paralytic Oh, that would be the reply in which you fail -- for the fifth time, at least -- to answer the question "why do you need this information?" I'm going to repeat -- ONCE -- the advice I gave you in my first response, with some elaboration: You almost assuredly do not need to know this. That you think you do is strongly sugggestive of a flawed design, and I recommend that you re-examine the entire concept. There is almost certainly a simpler method of accomplishing your purpose, whatever it is -- but since you won't tell us what that purpose is, it's pretty hard to help you achieve it. And *that* suggests that you don't clearly understand, yourself, what that purpose is. |
#27
| |||
| |||
|
|
On Mon, 08 Feb 2010 14:16:58 +0100, Johannes Keßler wrote: Question is: You have a single customer (identified by the customer id) and want to know at which place (perhaps this is the better word ?) it is by the specified ORDER BY. Go back to what Captain P said to you: You are asking about your solution again, not your problem. A problem is "I want to find the ten lowest active customer numbers so I can tell the customer if he is one of those" or "I want to tell the customer how many similar products cost more than what he bought". Don't describe this with SQL, don't use SQL terminology, don't even *think* about SQL for this. Since I do not store the place, I have to generate it every time I want this information by numbering the rows manually and then display the number which has the row with the correct customer id You WILL have to generate it every time, as described. Or stick it in a freshly-created table with an auto-increment value index so that you can keep the same sort for a while. It's a database, after all. Things are expected to change in it both frequently and rapidly. |
#28
| |||
| |||
|
|
I can think of a lot of reasons why this would be good - for instance, if the table holds an account balance, where does that customer rank in the list? Accounting would like to know that. Or maybe the table (more probably a view) holds the total sales. Marketing would like to know where that customer ranks in sales. A lot of reasons why one would want rankings. |
#29
| |||
| |||
|
|
On 08/02/10 14:57, Peter H. Coffin wrote: On Mon, 08 Feb 2010 14:16:58 +0100, Johannes Keßler wrote: Question is: You have a single customer (identified by the customer id) and want to know at which place (perhaps this is the better word ?) it is by the specified ORDER BY. Go back to what Captain P said to you: You are asking about your solution again, not your problem. A problem is "I want to find the ten lowest active customer numbers so I can tell the customer if he is one of those" or "I want to tell the customer how many similar products cost more than what he bought". Don't describe this with SQL, don't use SQL terminology, don't even *think* about SQL for this. Since I do not store the place, I have to generate it every time I want this information by numbering the rows manually and then display the number which has the row with the correct customer id You WILL have to generate it every time, as described. Or stick it in a freshly-created table with an auto-increment value index so that you can keep the same sort for a while. It's a database, after all. Things are expected to change in it both frequently and rapidly. But if you have a table with 10000 or even more rows, would it not be better to generate it with the given ORDER BY until the specified customerID is found? Since all other rows are useless after this row. |
#30
| |||
| |||
|
|
In article <hkp2tr$rc1$03$2 (AT) news (DOT) t-online.com>, =?UTF-8?B?Sm9oYW5uZXMgS2XDn2xlcg==?= <mail (AT) bananas-playground (DOT) net> wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 08/02/10 13:51, Doug Miller wrote: In article <hkov40$tnc$00$1 (AT) news (DOT) t-online.com>, =?ISO-8859-1?Q?Johannes_Ke=DFler?= <mail (AT) bananas-playground (DOT) net> wrote: Sorry if this is not as clear as it should be. here is an example customerid|name|price|points|sell - --------------------------------- 1|name1|10|22|1 2|name2|3|1|25 3|name3|15|84|23 4|name4|122|81|22 SELECT * FROM table ORDER BY price DESC result would be: customerid|name|price|points|sell - --------------------------------- 4|name4|122|81|22 3|name3|15|84|23 1|name1|10|22|1 2|name2|3|1|25 Now I want to know where in the list or at what possition a specific customer is. If I sort by price, customer 3 is at place 2. If I sort by points it would be at place 1. But right now there is no such information at which possition the customer is, I got this only by numbering the rows manually as described as my previous reply. Now the problem is that everytime I want to get a possiton I need to query the whole table with a different ORDER BY. And then number the rows manually. If the table has 10000 rows you have to number 10000 rows. And you have the data from 10000 rows. Image if the customer is at possition 3 you could only number until you reach this specific customer AND do not have to number all the 10000 rows, just to find out that the customer is a row 3. numbering all the other 9997 rows is useless and a wast of data which is pulled from the table. So my question is if I can create a query which just does this without getting all the data. I hope it is more clear now. But english is not my primary language. Yes, *that* much is clear. What is still unclear is why you think it is important to know what position that customer is in the table. see my reply to Captain Paralytic Oh, that would be the reply in which you fail -- for the fifth time, at least -- to answer the question "why do you need this information?" I'm going to repeat -- ONCE -- the advice I gave you in my first response, with some elaboration: You almost assuredly do not need to know this. That you think you do is strongly sugggestive of a flawed design, and I recommend that you re-examine the entire concept. There is almost certainly a simpler method of accomplishing your purpose, whatever it is -- but since you won't tell us what that purpose is, it's pretty hard to help you achieve it. And *that* suggests that you don't clearly understand, yourself, what that purpose is. |
![]() |
| Thread Tools | |
| Display Modes | |
| |