MySQL group

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>&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-17-2007
jbl
 
Posts: n/a
Default MySQL group

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?

Reply With Quote
  #2 (permalink)  
Old 09-17-2007
Shelly
 
Posts: n/a
Default 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 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
}
}




Reply With Quote
  #3 (permalink)  
Old 09-18-2007
jbl
 
Posts: n/a
Default Re: MySQL group

> 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.

Reply With Quote
  #4 (permalink)  
Old 09-18-2007
Jerry Stuckle
 
Posts: n/a
Default Re: MySQL group

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
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0