java - sql groupby problem of getting quantity
滿天的星座
滿天的星座 2017-06-28 09:22:37
0
2
864


As shown in the picture, I now have 3 tables. tbh and toi are in a one-to-one relationship, and toi and togi are in a one-to-many relationship.
Now I query (the current situation is that a certain row of toi corresponds to 2 rows of togi)
Directly select* only gets one row of data, but
when I select count() gets 2, what's going on? How to write so that count( or other columns) will be 1?

====================================
Because in addition to the number of rows, I also need to get For other values, if it is just the number of rows, I can select * first and then get the size in java. Now I want to get both other values ​​and the number of rows at once

滿天的星座
滿天的星座

reply all(2)
学习ing

You get one row because you used group by. Count is an aggregate function that calculates the number of rows. Group by does not use an aggregate function and only takes the first row of data

某草草

================================Correct answer================ ==================
In this way, you can first query togi according to the conditions to get the results that meet the conditions, and then get the conditions of toi after removing duplicates, and then query toi and tbh

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!