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

  • Home
  • SEARCH
  • 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 6072563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:10:26+00:00 2026-05-23T10:10:26+00:00

I am writing a program in C# that read and writes to SQLite (System.Data.Sqlite)

  • 0

I am writing a program in C# that read and writes to SQLite (System.Data.Sqlite)
I have a table that looks like this

UserID  ProdID  Value1  Value2  TIME
------------------------------------------------
1        1      10      1      2011-06-01 10:20:30.333
1        2      20      3      2011-06-01 10:20:30.444
2        1      100     11     2011-06-01 10:20:30.333
2        2      22      32     2011-06-01 10:20:30.444
1        1      20      2      2011-06-01 10:30:30.333
1        2      30      4      2011-06-01 10:30:30.444
2        1      22      22     2011-06-01 10:30:30.333
2        2      33      44     2011-06-01 10:30:30.444
1        1      10      1      2011-06-02 10:20:30.333
1        2      20      3      2011-06-02 10:20:30.444
2        1      11      11     2011-06-02 10:20:30.333
2        2      22      32     2011-06-02 10:20:30.444
1        1      20      2      2011-06-02 10:30:30.333
1        2      30      4      2011-06-02 10:30:30.444
2        1      22      22     2011-06-02 10:30:30.333
2        2      33      44     2011-06-02 10:30:30.444

I need to get Three things from this for each user.

1) The Last Entry of the day from each product for Value1 and 2 and totaled so its one two values that are the sum of all the products.
ie for user 1 on 2011-06-01 it would be Value1=50 and Value2=6.

curently i use:

SELECT * FROM TickData AS a,;
(SELECT USERID, DATE(TIME) AS JUSTDATE, MAX(TIME) AS MTIME;
FROM TickData;
GROUP BY 1,2;
) AS b;
WHERE a.USERID = b.USERID;
AND a.TIME = b.MTIME;
AND STRFTIME('%Y-%m',a.TIME) = STRFTIME('%Y-%m','NOW');
AND a.USERID = 1;

this returns:

UserID  ProdID  Value1  Value2  TIME
------------------------------------------------
1        1      20      2      2011-06-01 10:30:30.333
1        2      30      4      2011-06-01 10:30:30.444

For 2011-06-01.
Then i loop through the data and add the values when the dates are the same.
Giving me Value1=50 and Value2=6.

2) The Highest Entry for each day of Value1 totaled for all products.
ie for user 2 on 2011-06-01 it would be Value1=133.

UserID  ProdID  Value1  Value2  TIME
------------------------------------------------
2        1      100     11     2011-06-01 10:20:30.333
2        2      33      44     2011-06-01 10:30:30.444

3) The Lowest Entry for each day of Value1 totaled for all products.
ie for user 2 on 2011-06-01 it would be Value1=44.

UserID  ProdID  Value1  Value2  TIME
------------------------------------------------
2        2      22      32     2011-06-01 10:20:30.444
2        1      22      22     2011-06-01 10:30:30.333

I havent had any luck with 2 or 3 yet.

Does anyone have any sugestions

  • 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-23T10:10:27+00:00Added an answer on May 23, 2026 at 10:10 am

    Ok worked it out my self over the weekend

    1)

    SELECT sum(value1), sum(value2) FROM TickData AS a,
    (SELECT USERID, PRODID, DATE(TIME) AS JUSTDATE, MAX(TIME) AS MTIME
    FROM TickData
    GROUP BY 1,2,3
    ) AS b
    WHERE a.USERID = b.USERID
    AND a.TIME = b.MTIME
    AND STRFTIME('%Y-%m',a.TIME) = STRFTIME('%Y-%m','NOW')
    AND a.USERID = 1
    GROUP BY JUSTDATE
    

    2)

    SELECT sum(Mval) FROM TickData AS a,
    (SELECT USERID, PRODID, DATE(TIME) AS JUSTDATE,ID, MAX(value1) AS Mval
    FROM TickData
    GROUP BY 1,2,3
    ) AS b
    WHERE a.USERID = b.USERID
    AND a.ID = b.ID
    AND STRFTIME('%Y-%m',a.TIME) = STRFTIME('%Y-%m','NOW')
    AND a.USERID = 2
    GROUP BY JUSTDATE
    

    3)

    SELECT sum(Mval) FROM TickData AS a,
    (SELECT USERID, PRODID, DATE(TIME) AS JUSTDATE,ID, MIN(value1) AS Mval
    FROM TickData
    GROUP BY 1,2,3
    ) AS b
    WHERE a.USERID = b.USERID
    AND a.ID = b.ID
    AND STRFTIME('%Y-%m',a.TIME) = STRFTIME('%Y-%m','NOW')
    AND a.USERID = 2
    GROUP BY JUSTDATE
    

    Edit:
    2 and 3 can be done with one query:

    SELECT sum(Mval), sum(Mval2) FROM TickData AS a,
    (SELECT USERID, PRODID, DATE(TIME) AS JUSTDATE,ID, MAX(PL) AS Mval,MIN(PL) AS Mval2
    FROM TickData
    GROUP BY 1,2,3
    ) AS b
    WHERE a.USERID = b.USERID
    AND a.TIME = b.MTIME
    AND STRFTIME('%Y-%m',a.TIME) = STRFTIME('%Y-%m','NOW')
    AND a.USERID = 2
    GROUP BY JUSTDATE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I'm writing a program that needs to read and write lots of data in
In a program that I'm writing, I wanted to make a ConfigParser that's read
I am writing a program that does a lot of writes to a Postgres
I have an application written in VB6 that writes data to a spreadsheet. I'm
I am writing a program that needs to read a set of records that
I am writing a C program that will read and write from/to a serial
I 'm writing a little program that implements pipes like they work in the
I have to write a program that read from a file that contains the
I am writing a program that will read and write characters, converting lowercase characters

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.