php - How to create a SQL query for the given scenario? -


there table named user_transaction has following structure:

transaction_id    mediumint(6)   unsigned (pk) transaction_no    varchar(55) transaction_cc_avenue_no    varchar(55) transaction_card_category    varchar(100) transaction_user_id      varchar(32) transaction_user_name    varchar(255) transaction_user_email_id    varchar(255) transaction_deal_code    varchar(10) transaction_dc_id    smallint(4) transaction_amount    float(10,2) transaction_discount    float(10,2) transaction_total_amount    float(10,2) transaction_data_assign    enum('0', '1') transaction_status    enum('success', 'inprocess', 'fail', 'cancelled')      transaction_date    bigint(12) transaction_update_date    bigint(12) transaction_update_user_id    varchar(32) 

i'm using unix timestamp values in fields transaction_date , transaction_update_date store dates. issue i'm getting today's date in format dd/mm/yyyy say(11/07/2013) form in php. after getting date want find out following counts today(i.e. 11/07/2013) only:

total count of transactions carried out, total count of transactions having transaction_status 'success',   total count of transactions having transaction_status 'inprocess', total count of transactions having transaction_status 'fail', total count of transactions having transaction_status 'cancelled' 

the same output required 2 dates(range of 2 dates both dates inclusive). i'm newbie in unix timestamp manipulations. can me in regard? in advance.

select  count(*) `carried out`,         sum(transaction_status = 'success') `success`,         sum(transaction_status = 'inprocess') `inprocess`,         sum(transaction_status = 'fail') `fail`,         sum(transaction_status = 'cancelled') `cancelled`    tablename --  add conditions here 

and since want records today's date only, assuming transaction_date can convert unix date date, eg

where  from_unixtime(transaction_date) >= curdate() ,        from_unixtime(transaction_date) < curdate() + interval 1 day 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -