Tenho a seguinte query:
$qrysel = "select * from won_auctions w left join registration r on w.userid=r.id where payment_date!='0000-00-00 00:00:00'";
Essa query vai mostrar uma lista de usuários da tabela won_auctions e pegar o nome do usuário na tabela registration.
A ideia é que ele verifique quantos registros tem cada usuário na tabela won_auctions durante o mês atual, e o total.
A data pode ser verificada pela coluna payment_date, e o usuário pela coluna userid, da tabela won_auctions
No caso:
$total_arrematados = xxx;
$total_este_mes = xxx;
Eu criei uma tabela e pensei em usar o while para mostrar os resultados, só que preciso que ele mostre apenas uma linha por usuário, e não várias linhas para o mesmo usuário.
Preciso também ordenar para exibir os que tem mais registros por primeiro, para o mês atual.
Estrutura won_auctions:
`id` int(11) NOT NULL AUTO_INCREMENT,
`auction_id` int(11) NOT NULL DEFAULT '0',
`accept_denied` varchar(100) NOT NULL DEFAULT '',
`userid` int(11) NOT NULL DEFAULT '0',
`won_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`accept_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`payment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`invoice_flag` enum('0','1') NOT NULL DEFAULT '0',
`situacaodescr` varchar(50) NOT NULL,
`dataenvio` datetime NOT NULL,
`rastreamento` varchar(100) NOT NULL DEFAULT '',
`lances_creditados` enum('SIM','NAO','REMOVIDO','') NOT NULL DEFAULT '',
`transacao_ps` varchar(35) NOT NULL DEFAULT '',
`cancelado` enum('SIM','NAO') NOT NULL DEFAULT 'NAO',
`cancelado_motivo` varchar(1000) NOT NULL DEFAULT '',
Estrutura registration:
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL DEFAULT '',
`firstname` varchar(100) NOT NULL DEFAULT '',
`lastname` varchar(100) NOT NULL DEFAULT '',
*
com funções de agregação vai ficar complicado. Se possível, acesse o SQLFiddle e monte o banco de dados com algumas informações para facilitar quem tentar te ajudar