0

I have a database in which there is a user table & how many time they reward record table I wanna result like this (WEEK WISE)

user_name user_week user_reward
abc          24,25,26    4,5,6

My query is like this

SELECT WEEK(cpd.added_date),COUNT(cpd.result)
FROM cron_players_data cpd WHERE cpd.player_id = 81
AND cpd.result = 2 AND cpd.status = 1
GROUP BY WEEK(cpd.added_date);

And Result is

user_name user_week user_reward
abc          24    4
abc          24    5
abc          24    6

i use group_concat with count but its useless is there any alternate method for this desire result

1
  • The user_* columns do not appear in your query. Commented Jun 28, 2012 at 5:43

1 Answer 1

1

You have 2 level grouping, first week, and then username, so i sugest you use a subquery for that first grouping like:

SELECT
 user_name,
 GROUP_CONCAT(user_week) AS user_weeks, 
 GROUP_CONCAT(user_reward) AS user_rewards
FROM (
  SELECT
   user_name,
   WEEK(cpd.added_date) AS user_week,
   COUNT(cpd.result) AS user_reward
  FROM cron_players_data AS cpd 
  WHERE
   cpd.player_id = 81 AND
   cpd.result = 2 AND
   cpd.status = 1
  GROUP BY user_week
) as temp
GROUP BY user_name;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.