Jump to content

How Select data from mysql 3 tables with conditition


Tejpal

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 comment
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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...