When sql select, what should I do if I want to see the general column and the column with the count function applied at the same time?

Asked 1 years ago, Updated 1 years ago, 129 views

Table_1 shows the picture below It has a number and its corresponding name.

And table_2 has numbers.

select number, name from table_1

Can I check the number and name of table_1 by selecting it as above and check how many times the number exists in table_2 at once?

select one.number, one name, count(two.number) from table_1one
left join(?) table_2 two ~~~
group by two.Number

I want to select it right away like this, but I don't know how...

sql mssql select join count

2022-09-20 20:18

1 Answers

select
    one.number,
    max(one.name) AS name,
    Count (two.number) AS count
FROM Table1 one
JOIN Table2 two on two. Number = one. Number
GROUP BY ONE.Number /* You must group with this to compute the rest. */

DEMO


2022-09-20 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.