Note that there are some explanatory texts on larger screens.

plurals
  1. POAchieve data between particular date in Mysql
    primarykey
    data
    text
    <p>I have three tables named <code>User</code>,<code>Role</code> and <code>Balance_updates</code>. <code>User</code> table hold info about user,<code>Role</code> depicts type of user like Customer,Admin,Manager and <code>Balance_updates</code> store all transaction regarding balance i.e it store history about transaction related to balance.</p> <p><strong>Tables</strong></p> <p>User</p> <pre><code>+-----------------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+--------------+------+-----+-------------------+-------+ | username | varchar(20) | NO | PRI | NULL | | | password | varchar(32) | NO | | NULL | | | email | varchar(50) | YES | | NULL | | | role_id | int(11) | NO | MUL | NULL | | | mobile_wallet_balance | double(20,2) | NO | | 0.00 | | | merit_point | bigint(20) | YES | | NULL | | | status | int(11) | NO | | NULL | | | is_auto_btm_enabled | tinyint(1) | YES | | 0 | | | created_at | datetime | YES | | NULL | | | updated_at | timestamp | YES | | CURRENT_TIMESTAMP | | | gender | varchar(20) | YES | | NULL | | | validity | date | YES | | NULL | | | status_desc | text | YES | | NULL | | +-----------------------+--------------+------+-----+-------------------+-------+ Role +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(25) | NO | UNI | NULL | | | description | varchar(255) | YES | | NULL | | | value | varchar(25) | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+ </code></pre> <p>Balance_updates</p> <pre><code>+------------+--------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+-------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | username | varchar(15) | NO | | NULL | | | role_id | int(11) | YES | | NULL | | | amount | double(20,2) | YES | | NULL | | | updated_at | timestamp | NO | | CURRENT_TIMESTAMP | | +------------+--------------+------+-----+-------------------+----------------+ </code></pre> <p>Data in Balance_updates</p> <p><strong>Objective</strong></p> <p>I want to generate all users and their respective balance in any given date; For example if i want the balance statement for a given date <code>2012-12-28</code> it should generate latest balance from <code>Balance_updates</code>.</p> <p><strong>What I have tried</strong></p> <pre><code>SELECT DISTINCT ( u.username ), r.value, u.amount AS `amount` FROM Balance_updates u INNER JOIN Role r ON u.role_id = r.id WHERE u.amount &gt; 0.0 &amp;&amp; UNIX_TIMESTAMP( u.updated_at ) &lt; UNIX_TIMESTAMP( '2013-1-3 23:59:59' ) ORDER BY r.value, UNIX_TIMESTAMP( u.updated_at ) DESC </code></pre> <p><strong>RESULT and PROBLEM</strong></p> <p>As you expect it is returning all values from Balance_updates i.e every other User transaction recorded.</p> <p>Question:</p> <p>1.How can i achieve latest balance statement of a user in a particular date.If in that date user balance is not changed then show his balance in previous time last changed.</p> <p>Any help will be appreciated;</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload