how to simplify this statement? php mysql -
i need retrieve multiple selects mysql table, need simplify statements
these statements
$stardate=dateselect $enddate=dateselect select count(distinct(customer)) client my_table date_field between'$startdate' , '$enddate' select count(distinct(customer)) computeris1 my_table computer=1 , date_field between'$startdate' , '$enddate' select count(distinct(customer)) computeris2 my_table computer=2 , date_field between'$startdate' , '$enddate'
i have 10 fields, each 1 has 4 or 5 values (choices) want count distinct client each field (e.g. computer) , between 2 dates..
another problem date timestamp of mysql, doesn't homecoming right , exclude today's records unless select end date tomorrow works, think time issue, how can create count date correctly discarding time?
you can prepare date/time problem using date()
. rest, can utilize conditional aggregation in 1 query:
select count(distinct(customer)) customer, count(distinct case when computer = 1 client end) computer1, count(distinct case when computer = 2 client end) computer2 my_table date(date_field) between '$startdate' , '$enddate';
this puts values separate columns rather separate rows.
php mysql sql
No comments:
Post a Comment