如何在sqlserver中实现这一点
select firstname,count(*) from
(select distinct firstname,lastname,amount
from emp)
group by firstname
这适用于oracle。
答案 0 :(得分:0)
我不明白你想做什么,但你的查询可以这样写:
SELECT firstname, COUNT(*)
FROM emp
GROUP BY firstname;
或强>
select firstname, count(*)
from
(
select distinct firstname, lastname, amount
from emp
) AS t
group by firstname;
您还可以使用DISTINCT
内的COUNT
关键字;像这样:COUNT(DISTINCT columnanme)
代替。
或强>
select firstname, lastname, amount, COUNT(*)
from emp
group by firstname, lastname, amount;
答案 1 :(得分:0)
以下是一些我工作的东西的例子基本上是一样的:
SELECT SYS_CSL, COUNT(SYS_CSL)
FROM (
SELECT SYS_CSL
FROM [VANTAGE_READ].CSL_SERV_RANK
WHERE AGNT_CSL = 0
AND (STOP_DTE_CSL > GETDATE() OR STOP_DTE_CSL IS NULL)
) t1 GROUP BY sys_csl
答案 2 :(得分:0)
您需要命名派生表
select firstname, count(*)
from (select distinct firstname,lastname,amount from emp) derived
group by firstname