473,396 Members | 1,712 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,396 software developers and data experts.

select multiple values from mysql between intervals

hi all

please help...

i would like to get datas between certain intervals.
please have a look @ db_table.jpg, it's the db structure. the red highlighted part is the value i need.

condition is select values when both device one & device two are off.

db_table_report.jpg is the resulting report format. It contains start time & end time and the duration..

please help, i know it's a bit complicated, but it's urgent.
Attached Images
File Type: jpg db_table.jpg (55.0 KB, 310 views)
File Type: jpg db_table_report.jpg (19.0 KB, 186 views)
Jan 12 '12 #1
6 2350
Rabbit
12,516 Expert Mod 8TB
Do a min and max aggregate query grouping by the remark and that will give you the start and end. Then you can use the datediff function to calculate the duration.
Jan 12 '12 #2
rabbit i tried
Expand|Select|Wrap|Line Numbers
  1. SELECT MIN(`Time`) AS start_time, MAX(`Time`) AS end_time
  2. FROM table_name
  3. WHERE `Device one` = 'OFF'
  4.   AND `Device two` = 'OFF'
  5. GROUP BY `Remarks`
  6.  
i got the result from above query, but no duration.
i am playing with mysql datedif & subtime functions, but no results yet. datediff gives resulting days no time and subtime gives need input as time no dates allowed before, and all these should work in less time.

my date format is like 2011-12-03 22:06:42 and 2011-12-06 16:18:14
Jan 13 '12 #3
Rabbit
12,516 Expert Mod 8TB
Well, you have to use DateDiff to get the number of minutes between the two dates and then calculate the elapsed days, hours, and minutes yourself.
Jan 13 '12 #4
I used mysql TIMEDIFF, it's working as intended.
so my query is like

Expand|Select|Wrap|Line Numbers
  1. "SELECT MIN(`time`) AS start_time, MAX(`time`) AS end_time,`remarks`, TIMEDIFF(MAX(`time`), MIN(`time`)) AS duration
  2. FROM `db_table`                                WHERE `time` BETWEEN '$predate' AND                                                                                                                                                                                               '$datenow'                                        AND `device one` = 'OFF'                                              AND `device two` = 'OFF'                                            GROUP BY `remarks` ORDER BY `time` DESC"
  3.  
this gives the needed result,
but is there any way to speed up the process, now it takes around 10 seconds to load the result
Jan 16 '12 #5
Rabbit
12,516 Expert Mod 8TB
Look at the execution plan and then create the appropriate indexes.
Jan 16 '12 #6
u r right Rabbit

i am changing 'on', 'off' varchar fields to tinyint numeric 1 or 0. there is total 450000+ rows. thanks Rabbit
Jan 17 '12 #7

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

Similar topics

6
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2...
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
4
by: LD | last post by:
Is there a way in Access to store more than one value in a field that has been selected from a combo box? For example, if a combo box had three values that you can select, "One", "Two", and...
2
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the...
1
by: sverdlov | last post by:
Hi all, I have, let's say, 1 column called Payment_type. In the column, there are 6 types of values: 1, 2, 3, 4, 5, 6, like in --------------------------------- Payment_type |...
1
by: ykong1214 | last post by:
In my project, there is a single select tag, <html:select property="userName" size="7"> <html:options collection="UserList" property="value" labelProperty="label" /> </html:select> ...
3
tolkienarda
by: tolkienarda | last post by:
hi all i am trying to make a selection box where people can select multiple items then those items will become values assigned to a variable. i am actualy using this in a php/mysql program but i...
2
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for...
5
by: sarayu | last post by:
Hi All, How can i select multiple values in a form without using options.I want to select more than one image from a table and submit those selected values as a request to the next page.I don't...
3
by: jeremyjcochran | last post by:
I am writing a code for a shopping cart, the customer selects the color, which also has the price. I want to send the color and the price to "price" and "color" on the mysql server. How do I code a...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.