473,666 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query for max date value for each item in a WHERE IN clause

20 New Member
Hello,

I am trying to query the data set below for the data_value for the data_id of the recent data_date.

So for data_id 18554 the recent data_date will be 2/8/2016 18:40 and its data_value will be 29504.76

And for data_id 18555 the recent data_date will be 2/8/2016 18:40 and its data_value will be -90909090909

Expand|Select|Wrap|Line Numbers
  1. data_id    data_name    data_date    data_value
  2. 18554    traffic_in    2/8/2016 18:30    30737.11333
  3. 18554    traffic_in    2/8/2016 18:10    31780.68
  4. 18554    traffic_in    2/8/2016 18:35    30338.82
  5. 18554    traffic_in    2/8/2016 18:15    31393.36667
  6. 18554    traffic_in    2/8/2016 18:40    29504.76
  7. 18554    traffic_in    2/8/2016 17:50    32225.28
  8. 18554    traffic_in    2/8/2016 18:00    32225.32
  9. 18554    traffic_in    2/8/2016 17:55    32240.71333
  10. 18554    traffic_in    2/8/2016 17:45    32602.98
  11. 18554    traffic_in    2/8/2016 18:20    30874.39333
  12. 18554    traffic_in    2/8/2016 18:25    30511.56
  13. 18554    traffic_in    2/8/2016 18:05    32090.84667
  14.  
  15. 18555    traffic_in    2/8/2016 18:15    -90909090909
  16. 18555    traffic_in    2/8/2016 18:35    -90909090909
  17. 18555    traffic_in    2/8/2016 17:45    -90909090909
  18. 18555    traffic_in    2/8/2016 18:00    -90909090909
  19. 18555    traffic_in    2/8/2016 17:50    -90909090909
  20. 18555    traffic_in    2/8/2016 17:55    -90909090909
  21. 18555    traffic_in    2/8/2016 18:10    -90909090909
  22. 18555    traffic_in    2/8/2016 18:20    -90909090909
  23. 18555    traffic_in    2/8/2016 18:05    -90909090909
  24. 18555    traffic_in    2/8/2016 18:25    -90909090909
  25. 18555    traffic_in    2/8/2016 18:40    -90909090909
  26. 18555    traffic_in    2/8/2016 18:30    0.213333333
  27.  
  28.  
The results i want is

Expand|Select|Wrap|Line Numbers
  1. data_id    data_name    data_date    data_value
  2. 18554    traffic_in    2/8/2016 18:40    29504.76
  3. 18555    traffic_in    2/8/2016 18:40    -90909090909
  4.  
But when i use the following MySQL statement
Expand|Select|Wrap|Line Numbers
  1. SELECT data_id,data_name,max(data_date),data_value FROM `data_source_` where `data_id` IN (18554,18555) AND data_name = 'traffic_in'
  2.  
this just gives me

Expand|Select|Wrap|Line Numbers
  1. data_id    data_name    data_date    data_value
  2. 18554    traffic_in    2/8/2016 18:40    29504.76
  3.  
Help will be very much appreciated.

Thanks
Feb 8 '16 #1
1 1896
hsriat
1,654 Recognized Expert Top Contributor
Something's missing...
Expand|Select|Wrap|Line Numbers
  1. group by
Feb 27 '16 #2

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

Similar topics

3
8735
by: Mike | last post by:
I have a mulitpage form that I do not record the information into a dbase until the end. I need to pass the field values form on form to the next. I have the code for automatically generating the 'hidden fields' but cannot figure out how to code it to automatically generate the assignment statements. For example:
1
17320
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN dateadd(year,1,dateadd(month,-1,getdate())) AND dateadd(day,-1,(dateadd(month,1,dateadd(year,1,dateadd(month,-1,getdate()))))) *************** (first part of the date calculation comes out to be '2005-05-01' and
4
14231
by: Corey | last post by:
All, I am relatively new to XML and I have what may sound like a dumb question. I want to pass a query string variable to my xml document and filter the output based on that variable. For example, if I type in www.mysite.com?geid=0000123468 I want to display only AccessReview/Report where GEID='0000123468'. I appreciate any help you can provide. Corey
2
2089
by: jmev7 | last post by:
I had a query with a criteria in a date field reading "> And <", and when run, it correctly prompted first for the param, and then for the param. I then created functions to replace these params using an input box so that I could control the default date in each case (based on the current day of week and other variables). Each function works correctly, but for some reason, the first prompt is for , and the second prompt is for , which...
8
2183
by: TGEAR | last post by:
I have an ItemSTDPriceHistory table as below and this is a child table of itemlookup table with one to many relationship. if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table . GO
3
3504
by: jef3fowler | last post by:
Drawn a blank. Looking to find the last date each client ordered something. The query should show each client and the last order date. 2 tables: Clients and orders. clientID in each. Any hints/directions appreciated. Even blistering attacks on my ability.
2
4172
by: dauwe.peter | last post by:
A table : Nameperson, Book nr, Bookdatein, Bookdateout, CD nr, cddatein, cddateout, dvd nr, dvddatein, dvddateout. I would like a query where a see the personsname en de last book with the datein and out , the last cd with datein and out , and the same for the dvd. Because the last time the person came he toke only a book but dit not return his dvd (for example). But with one click i would like to see the last of every item with the...
2
2878
by: liz0001 | last post by:
I am trying to run an SQL query for each item in an Array using ASP. I have coded it as such. IDsArray() is an array of integers. ArrayLength=15 sqlGetiIDs = "SELECT * FROM Table1 WHERE (dID = " & IDsArray(j) & ")" j=0 Dim GetiIDsRSArray(ArrayLength)
19
6013
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the original tread http://bytes.com/topic/access/answers/872005-query-date-range Just to clarify what I am trying to achieve....
6
1813
by: jase7678 | last post by:
I have a database containing an ItemTypesColors table which has a 1:Many relationship with an ItemDescription table which has a 1:Many relationship with an ItemVendor table. The ItemTypesColors table comprises Item Type & Color, eg: Shirts|White, Shirts|Black, Jeans|Blue etc. The ItemDescription table contains the number of items in a package, a link to the ItemVendor table, price etc. The ItemVendor table contains the Vendor name, a...
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.