Jump to content

How Select data from mysql 3 tables with conditition


Recommended Posts

Hello Every One

I Want Show all USer last Useges Data From date of Last Recharge to To Date and condition With user owner by

 

i Have 3 Table

invoice - Need data from column date(need last invoice Last Recharge date For Below Table Condition Start ),username( Uniq In all table)

acct - > Need data from column acctstarttime( For Start Date ),SUM( acct.acctinputoctets + acct.acctoutputoctets ) AS data(For Sum Of Useges Data ),SUM( acct.acctsessiontime ) AS acctsessiontime,username(Uniq In all table)

users - > Need data from column username( Main Table Match username on this table base),owner,lastlogoff,expiration,uptimelimit,comobolimit,

 

My Code is Here But Not working

SELECT DATE( `acctstarttime` ) AS acctstarttime, SUM( acct.acctinputoctets + acct.acctoutputoctets ) AS data, acct.username, SUM( acct.acctsessiontime ) AS acctsessiontime, users.username, users.owner, users.lastlogoff, users.expiration, users.uptimelimit, .comblimit, users.enableuser,invoices.date
FROM invoices,acct
JOIN users ON acct.username = rm_users.username
WHERE users.owner = 'admin' and acctstarttime between 'invoice.date' and 'users.expiration'
GROUP BY MONTH( `acctstarttime` ) , acct.username
ORDER BY invoices.date DESC
LIMIT 0 , 30
I Think Problem in Where condition i want acctstarttime between 'invoice.date(Desc or User last recharge Date)' and 'users.expiration'
I m very Confused How I dow Any One Can Help Thanks in Extra
Edited by Tejpal
Link to post
Share on other sites

acctstarttime between 'invoice.date' and 'users.expiration'

If you're trying to refer to columns in the table, do not put quotes around them. Quotes are for text, you're telling it to find records that are between the text "invoice.date" and "users.expiration".
  • Like 1
Link to post
Share on other sites

m Also use acctstarttime between 'invoice.date' and 'users.expiration' and acctstarttime between invoice.date and users.expiration but Result Not Right But when I Use Static Date both then working good can you explain sir how i done

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...