Discussion: MySQL group
Afficher un message
Vieux 17/09/2007, 18h25   #2
Shelly
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL group


"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 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
}
}




  Réponse avec citation
 
Page generated in 0,05796 seconds with 9 queries