This is a discussion on MySQL group within the PHP Language forums, part of the PHP Programming Forums category; Hello. I would like to select only changes in value: time (datetime) bits (integer) in command: select time,(bits>&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello.
I would like to select only changes in value: time (datetime) bits (integer) in command: select time,(bits>>8)&1 as P from VV order by time I view this result: time P 12:23:11 0 12:23:16 0 12:24:01 0 12:24:10 1 12:24:23 1 12:24:45 0 12:25:01 0 12:25:34 1 12:25:59 1 And how to obtain this result: 12:23:11 0 12:24:10 1 12:24:45 0 12:25:34 1 The group clause selects only two rows: 12:23:11 0 the first "0" value 12:24:10 1 the first "1" value Can you help me? |
|
|||
|
"jbl" <jbl@profisystem.info> wrote in message news:1190049012.382175.69020@n39g2000hsh.googlegro ups.com... > Hello. > I would like to select only changes in value: > time (datetime) > bits (integer) > in command: > select time,(bits>>8)&1 as P from VV order by time > I view this result: > time P > 12:23:11 0 > 12:23:16 0 > 12:24:01 0 > 12:24:10 1 > 12:24:23 1 > 12:24:45 0 > 12:25:01 0 > 12:25:34 1 > 12:25:59 1 > > And how to obtain this result: > 12:23:11 0 > 12:24:10 1 > 12:24:45 0 > 12:25:34 1 > > The group clause selects only two rows: > 12:23:11 0 the first "0" value > 12:24:10 1 the first "1" value > > Can you help me? > I don't know how you could do this automatically with sql, but you could foreach your way through the set, remembering the last P value and, if it changes, then ooutput that row and reset the the remembered P value. Here is some pseudocode. P0 = 2; foreach loop { read next row from returned mysql query resource get P and time from this row if (P != P0) { P0 = P; output time and P } } |
|
|||
|
> Here is some pseudocode.
> > P0 = 2; > foreach loop { > read next row from returned mysql query resource > get P and time from this row > if (P != P0) { > P0 = P; > output time and P > } > > } I'm using this solution, but on the client side. If the connection is over the internet, this is a very long way to get results. |
|
|||
|
jbl wrote:
>> Here is some pseudocode. >> >> P0 = 2; >> foreach loop { >> read next row from returned mysql query resource >> get P and time from this row >> if (P != P0) { >> P0 = P; >> output time and P >> } >> >> } > I'm using this solution, but on the client side. > If the connection is over the internet, this is > a very long way to get results. > This is not a MySQL group. This is a PHP group. Notice the name? If you're asking MySQL questions, you need to be in a MySQL group. If you're asking for a PHP solution, just what are you asking for? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |