# 如何在SELECT语句中重命名和引用COUNT（*）？

##### 问题描述投票：-1回答：3

``````SELECT
school_name,
(SELECT COUNT(*)
FROM liason_to
WHERE school_name = s.school_name)
FROM school s;
``````

``````SELECT
school_name,
(SELECT COUNT(*) AS numLiasons
FROM liason_to
WHERE school_name = s.school_name)
FROM school s
WHERE numLiasons > 0;
``````

sql oracle nested-queries
##### 3个回答
1

``````SELECT school_name,
(SELECT count(*)
FROM liason_to l
WHERE l.school_name = s.school_name) AS numliasons
FROM school s;
``````

``````SELECT school_name,
(SELECT count(*)
FROM liason_to l
WHERE l.school_name = s.school_name) numliasons
FROM school s;
``````

``````SELECT school_name,
(SELECT count(*)
FROM liason_to l
WHERE l.school_name = s.school_name) numliasons
FROM school s
WHERE (SELECT count(*)
FROM liason_to l
WHERE l.school_name = s.school_name) > 0;
``````

1

``````SELECT s.school_name, COUNT(*) as my_count
FROM school s
INNER JOIN liason_to l on s.school_name = l.school_name
GROUP BY s.school_name
``````

``````SELECT
school_name,
(SELECT COUNT(*)
FROM liason_to
WHERE school_name = s.school_name) as my_name
FROM school s;
``````

0

``````SELECT
t.school_name,
t.numLiasons
FROM (
SELECT
s.school_name,
(
SELECT COUNT(*)
FROM liason_to
WHERE school_name = s.school_name
) AS numLiasons
FROM school s
) t
WHERE t.numLiasons > 0;
``````