我有一个表,其中count为字段,用户名为另一个。通过使用此查询,我设法获得了相关月份的所有记录的总数:
((UNIX_TIMESTAMP(orders.created_at) - UNIX_TIMESTAMP(table2.created_at) < 5400)
AND (UNIX_TIMESTAMP(orders.created_at) - UNIX_TIMESTAMP(table2.created_at) > 0))
OR ((UNIX_TIMESTAMP(table2.created_at) - UNIX_TIMESTAMP(orders.created_at) < 5400)
AND (UNIX_TIMESTAMP(table2.created_at) - UNIX_TIMESTAMP(orders.created_at) > 0))
我还设法通过此查询获取个人用户条目:
select count(*)
from forms
where Month(date) = MONTH(CURDATE())
AND YEAR(CURDATE());
所以......第一个给了我一些类似于&#39; 12&#39; ...另一个词,10月输入的12条记录(让我们说)。第二个查询给了我类似的东西:
约翰5 玛丽7我想要的是一个查询,它会给我每个用户条目的百分比......即约翰的41%。 12个参赛作品中的5个。
希望我明白......感谢您的帮助。
答案 0 :(得分:1)
加入使用分组查询计算总计的查询。
SELECT u_name, COUNT(*) AS numb, COUNT(*)*100/total AS pct
FROM forms
CROSS JOIN (SELECT COUNT(*) AS total
FROM forms
WHERE MONTH(date) = MONTH(NOW()) AND YEAR(date) = YEAR(NOW())) AS x
WHERE MONTH(date) = MONTH(NOW()) AND YEAR(date) = YEAR(NOW())