Jump to content

Need help with writing a query


hno

Recommended Posts

hi,

I have the following information in my database :

id user_id p_id

2 2 38 2011-10-10 08:36:32 1010

5 4 38 2011-10-10 08:37:51 110

28 2 46 2011-10-13 17:05:27 244

16 2 38 2011-10-10 17:49:40 234244

18 4 38 2011-10-11 20:05:04 2010

19 4 38 2011-10-11 20:05:42 2510

 

I want to the number of rows with p_id: 38 for every user_id.For example I want the reslult for p_id:38 for user_id:2 to be 2 and p_id:38

for user 4 to be 3 .

How should I write the query to return that?So ,I want to have the umber of rows for every user_id for a specific p_id.

I hope you get what I mean.

 

Thanks

Link to comment
Share on other sites

SELECT the user id, COUNT(1) AS count
FROM the table
GROUP BY the user id
WHERE the p_id is the value you want

 

Thanks a lot but what's wrong with this code :"SELECT  user_id, COUNT(1) AS count FROM bid_list GROUP BY  user_id  where bid_id = '40' "

it errors me "right syntax to use near 'where bid_id = '40' LIMIT 0, 30' at line 1"

 

Link to comment
Share on other sites

SELECT the user id, COUNT(1) AS count
FROM the table
GROUP BY the user id
WHERE the p_id is the value you want

 

Thanks a lot but what's wrong with this code :"SELECT  user_id, COUNT(1) AS count FROM bid_list GROUP BY  user_id  where bid_id = '40' "

it errors me "right syntax to use near 'where bid_id = '40' LIMIT 0, 30' at line 1"

 

Can anybody helps please?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.