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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:13:13+00:00 2026-06-14T22:13:13+00:00

I have an external 3rd party program export the database to mysql in real

  • 0

I have an external 3rd party program export the database to mysql in real time, and I want to show data for reporting. So, I can’t change the structure, because it’s being sync in real time.

The table structure is something like this

ID | Date       | Transaction
-----------------------------
12 | 2012-11-01 | 200
12 | 2012-11-02 | 250
12 | 2012-11-03 | 150
12 | 2012-11-04 | 1000
12 | 2012-11-05 | 225
....
13 | 2012-11-01 | 175
13 | 2012-11-02 | 20
13 | 2012-11-03 | 50
13 | 2012-11-04 | 100
13 | 2012-11-05 | 180
13 | 2012-11-06 | 195

The data are very large and keep getting bigger each day.

What I want to do is to build a report (view table) based on something like this:

ID | Date       | Transaction | Prev Day Transaction
----------------------------------------------------
12 | 2012-11-01 | 200         | 0
12 | 2012-11-02 | 250         | 200
12 | 2012-11-03 | 150         | 250
12 | 2012-11-04 | 1000        | 150
12 | 2012-11-05 | 225         | 1000
....
13 | 2012-11-01 | 175         | 0
13 | 2012-11-02 | 20          | 175
13 | 2012-11-03 | 50          | 20
13 | 2012-11-04 | 100         | 50
13 | 2012-11-05 | 180         | 100
13 | 2012-11-06 | 195         | 180

I just can’t get the fast select statement. Currently the original data is already 283,120 rows. And it will grow like 500 rows daily.

I’ve tried something like:

SELECT *, (SELECT transaction FROM table as t2 WHERE t1.id=t2.id 
AND t1.date>t2.date ORDER BY t2.date DESC LIMIT 0,1)
FROM table AS t1

It’s working, but the select statement is very slow. Most of the time, it’s getting cut of in the middle of the operation.

What I need help is a very fast sql statement, which later on I could use to build the view table.

  • 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-14T22:13:14+00:00Added an answer on June 14, 2026 at 10:13 pm

    See this link: http://sqlfiddle.com/#!2/54a5e/12

    select t.id,t.cDate,t.cTrans
      ,(case when @pID=t.id then @pTran else 0 end) as preT 
      ,(@pID :=t.id) as `tID`,(@pTran := t.cTrans) as `tTrans` 
    from tb_test_1 as t,(select @pID = 0, @pTran = 0) as t2
    order by id,cDate;
    

    tID and tTrans column must be retained, and cannot display on page.

    Please forgive me as I only know a little english!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a system in which the data is replicated from an external 3rd
Can we never refer any external 3rd party jar in independent ejb module (except
I have external html5 canvas that you can paint on some lines using your
I have an external file in php, outputed as json format I want the
I have an external device that spits out UDP packets of binary data and
I have a 3rd party library that's written in C. It exports all of
I have a row of records from a 3rd party, including a 3rd party
The issue is as follows: I have a 3rd party Eclipse plug-in installed and
Background I have a large number of fields that will be updating real time
In a WPF application, I have a 3rd party library that is publishing messages.

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.