Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
alstefani
Starting Member
2 Posts |
Posted - 2009-10-26 : 19:47:15
|
Ok guys,I'm new to this so please help meTable 1:aMakeFields: make_id, make_name Table 2: autoadsFields:ad_id,make_id,model_id,price,color etc.Need to count records on Table 2 by make_id and display make_nameLike this:make_name | CNTAlfa Romeo 3BMW 2Practically I need to know how many ads I have per car make (do not show makes with 0 ads)Any suggestions wil be appreciatedAlbano |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2009-10-26 : 23:58:15
|
| Select make_name,count(1)From aMake, autoadsWhere aMake.make_id=autoads.make_idGroup by make_name |
 |
|
|
alstefani
Starting Member
2 Posts |
Posted - 2009-10-27 : 10:41:49
|
| Hello, Thank you for the replyI also need the make_id on the results:Like this:make_name | make_id | CNT(count)Alfa Romeo | 39 | 3Do I need a join query? |
 |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2009-10-28 : 00:41:52
|
| Select make_name,aMake.make_id,count(1)FromaMake, autoadsWhereaMake.make_id=autoads.make_idGroup bymake_name,aMake.make_id |
 |
|
|
|
|
|