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 9232251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:16:10+00:00 2026-06-18T06:16:10+00:00

Here is the query I’m using to gather daily values from three different addresses,

  • 0

Here is the query I’m using to gather daily values from three different “addresses”, which reference different sensors in our system.

SELECT DISTINCT
    LEFT(changes.date_time, 6) AS 'date',
    changes.address AS 'address',
    (CASE WHEN changes.address IN (18) THEN - MAX(changes.value * types.multiplier) ELSE MAX(changes.value * types.multiplier) END) AS 'value'
FROM sensor.changes
INNER JOIN sensor.types ON changes.type = types.idx
WHERE
    changes.address IN (1, 4, 8)
    AND changes.date_time >= '12110100000000'
    AND changes.date_time <= '13050100000000'
GROUP BY LEFT(changes.date_time, 6),
    changes.address
ORDER BY changes.idx;

The first date contains the following values, with subsequent dates carrying the same addresses:

date   address value
130203 1        0.0160
130203 4        0.1220
130203 8       -0.0070

I want to combine these three values, address 1+4+8, into a single row for that date. I’ve attempted a SUM on the “value” column, but that results in an SQL error: #1111 - Invalid use of group function. Taking out the second GROUP BY column results in one value per date, but the value is not a sum of those values. Using a second query to format the result is OK, but I would prefer if the math was done in the first query because the database server is not local.

EDIT: to clarify what I need as the result:

date   address value
130203 1       0.131

The integer under the address column in this case doesn’t matter.

  • 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-06-18T06:16:12+00:00Added an answer on June 18, 2026 at 6:16 am

    You should add a grouping clause.

    SELECT Resdate,SUM(Res.address),SUM(Res.value)
    FROM
    (
    SELECT DISTINCT
        LEFT(changes.date_time, 6) AS 'date',
        changes.address AS 'address',
        (CASE WHEN changes.address IN (18) THEN - MAX(changes.value * types.multiplier) ELSE MAX(changes.value * types.multiplier) END) AS 'value'
    FROM sensor.changes
    INNER JOIN sensor.types ON changes.type = types.idx
    WHERE
        changes.address IN (1, 4, 8)
        AND changes.date_time >= '12110100000000'
        AND changes.date_time <= '13050100000000'
    GROUP BY LEFT(changes.date_time, 6),
        changes.address
    ORDER BY changes.idx
    ) AS Res
    GROUP BY Res.Date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I follow the tutorial here to query content from CSV file: http://rudesyle.wordpress.com/2008/01/28/using-linq-to-query-a-csv-file/ However, the
Here's my query SELECT * FROM wp_postmeta WHERE meta_value LIKE '.$_POST['username'].' AND meta_value LIKE
Here is my query Select Gender from Table The result pane shows 1 1
Here is the query that I am working on: SELECT `unitid`, `name` FROM apartmentunits
Ok so I've a SQL query here: SELECT a.id,... FROM article AS a WHERE
I have following query in which data is coming from a table and in
I've got a query here which does what it is supposed to but I'm
This query here is executed on 3 tables(students) one which makes a zero on
I'm using this query to list duplicate records SELECT DISTINCT column1 from table group
Got this here query: EXPLAIN SELECT persons.id AS id, ppm.first FROM myschema.persons INNER JOIN

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.