Person Table
ID FirstName LastName PersonalWealth
1 Hello Alest $10,000.00
2 Leeds United $20,000.00
3 Middle Brough $30,000.00
4 Arsenal Chelsey $40,000.00
5 Manchester United $50,000.00
6 Peter Mean $60,000.00
7 Hello Coward $60,000.00
Car Table
ID CarRego Model Make Manufacture Year PersonID
1 abc123 Van Toyota 2001 1
2 abc234 Ute Honda 2005 1
3 pio345 Hatchback Mitsubishi 1990 2
4 elf234 Hatchback Ford 1996 3
5 flo124 Hatchback Toyota 1992 4
6 asc234 hatchback Holden 1965 6
7 xyz hatchback Holden 1998 5
8 avc Van jhjhjkhk 1989 1
Here is the SQL code that i have
SELECT
Count(Car.ID) AS CountOfid1,
Car.Model
FROM person
INNER JOIN Car ON person.ID=Car.ID
GROUP BY Car.Model;
But it works with van saying 2 of them but in real there is 开发者_运维知识库only one owner how do i fix this?
Help would be much appreciated
Youl have to be a little more clear in your question ,im not sure what you want to achieve! if there is one owner per car then maybe setting the PK of car to owner then you ensure only own owner/car. That way you will never have dupe owners cos the pk will clash and youl get a PK exception if you try to add.
I am having a lot of trouble following this question but i see one clear problem
INNER JOIN Car ON person.ID=Car.ID
This does not make sense to me. I think what that line should read is
INNER JOIN Car ON person.ID=Car.OwnerID
Comparing primary keys to primary keys means nothing
here is the database for car
ID CarRego Model Make Manufacture Year PersonID
1 abc123 Van Toyota 2001 1
2 abc234 Ute Honda 2005 1
3 pio345 Hatchback Mitsubishi 1990 2
4 elf234 Hatchback Ford 1996 3
5 flo124 Hatchback Toyota 1992 4
6 asc234 hatchback Holden 1965 6
7 xyz hatchback Holden 1998 5
8 avc Van jhjhjkhk 1989 1
精彩评论