Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3598934
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:18:17+00:00 2026-05-18T20:18:17+00:00

I have this db storing sensors acquisition data, Acquisitions (acq) come from different Control

  • 0

I have this db storing sensors acquisition data,
Acquisitions (acq) come from different Control Units (cu) at fixed intervals (datetime)
Each Acquisition has many different measures stored in Data table

acq
    id  
    datetime 
    id_cu     

data          
    id        
    id_acq  
    id_meas
    value

I need this kind of view:

+---------------------+------+----+-----+
|      datetime       |  v1  | v2 |  v3 |
+---------------------+------+----+-----+
| 2010-09-13 00:05:00 | 40.9 |  1 | 0.3 |
| 2010-09-13 00:10:00 | 41.0 |  2 | 0.3 |
| 2010-09-13 00:15:00 | 41.1 |  4 | 0.3 |
+---------------------+------+----+-----+

AS:

  • v1 is data.value (for example a humidity)
    WHERE acq.id_cu=1 AND data.id_meas=100

  • v2 is data.value (for example a counter)
    WHERE acq.id_cu=2 AND data.id_meas=200

  • v3 is data.value (for example a temperature)
    WHERE acq.id_cu=3 AND data.id_meas=300

and so on up to dozens of combinations choosen by user

I ended up with this query but it takes forever on a very small amount of data compared to the one that will be in production

SELECT a1.datetime, d1.value, d2.value, d3.value
FROM
    acq a1, data d1
    JOIN acq a2, data d2
        ON a2.id=d2.id_acq AND a2.datetime=a1.datetime
    JOIN acq a3, data d3
        ON a3.id=d3.id_acq AND a3.datetime=a1.datetime
WHERE a1.id=d1.id_acq
    AND a1.id_cu=1 AND d1.id_meas=100
    AND a2.id_cu=2 AND d2.id_meas=200
    AND a3.id_cu=3 AND d3.id_meas=300

I guess it would be way faster to get data separately for each a1.id_centr=x AND d1.id_meas=y condition and then printing data tabled that way I want with my application.

What is the best (and correct) way to acheive this?

edit: assuming no lacks in acquisitions I mean running this:

SELECT datetime, value
FROM acq, data
WHERE acq.id=data.id_acq
    AND (
        id_cu=1 AND id_meas=100
        OR id_cu=2 AND id_meas=200
        OR id_cu=3 AND id_meas=300
    )
ORDER BY id_cu, id_meas

the splitting results by id_cu / id_meas change and showing results side by side using a programming language (like python + numpy) is matter of hundreths of seconds vs. … minutes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:18:17+00:00Added an answer on May 18, 2026 at 8:18 pm

    *Assuming DATETIME and data.id_acq and cu and id_meas all have indexes*, you could try a UNION query with dummy column placeholders and a kludgey MAX(). This ought to work if your data.values are not negative numbers (and if they are you could simply choose an extremely large negative number instead of zero as the dummy placeholder value, a number well outside the possible range):

        select FOO.datetime, max(FOO.v1), max(FOO.v2), max(FOO.v3)
        from
         (
    
         select acq.datetime, data.value as v1,0 as v2, 0 as v3
         from acq inner join data on acq.id = data.id_acq
         where acq.id_cu=1 and data.id_meas=100
    
         UNION
    
        select acq.datetime, 0 as v1, data.value as v2, 0 as v3
        from acq inner join data on acq.id = data.id_acq
        where acq.id_cu=2 and data.id_meas=200
    
        UNION
    
        select acq.datetime, 0 as v1, 0 v2, data.value as v3
        from acq inner join data on acq.id = data.id_acq
        where acq.id_cu=3 and data.id_meas=300
        ) as FOO
        group by FOO.datetime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this db storing sensors acquisition data, Acquisitions (acq) come from different Control
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have this: public string Log { get { return log; } protected set
I have this: If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then stTransactionPaymentID = editTransactionRow.pay_id 'Check for null
I have this java string: String bla = <my:string>invalid_content</my:string>; How can I replace the
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\
I have a string like this: string s = This is my string; I
I have this code: Dim pathString As String = HttpContext.Current.Request.MapPath(Banking.mdb) Dim odbconBanking As New
I have this class called Table: class Table { public string Name { get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.