我需要使用下面的示例数据来计算两列。
示例数据
Project Node
------------------
Project1 Node1
Project2 Node1
Project3 Node2
示例输出
3 Projects 2 Nodes
答案 0 :(得分:1)
我通常不会在没有尝试提取某些努力证据的情况下发布答案,但......
cmd.CommandText = "UPDATE Accounts SET " & _
"credits = '" & val(credit.Text) + 10 & "'" & _
"WHERE username = '" & Form1.txtuname.Text & '"
答案 1 :(得分:0)
尝试此查询
definesPresentationContext
答案 2 :(得分:0)
试试这个
SELECT CAST(COUNT(DISTINCT Project) as varchar(50))+' Projects '
+ CAST(COUNT(DISTINCT Node) as varchar(50))+ ' Nodes'
FROM dbo.YourTable
答案 3 :(得分:0)
select
count(project) as project,
count(distinct node) as node
from test;
答案 4 :(得分:0)
我不确定您为什么不想使用distinct
,因为您已对其他答案发表了评论,但这将在没有distinct
的情况下发挥作用。但是,它更加丑陋 - 除非您需要执行partition
或其他一些不允许distinct
的语法,否则通常不是一个好主意。
select max(DR_Nodes) as Nodes, max(DR_Projects) as Projects
from
(
select *
, dense_rank() over (order by node) as DR_Nodes
, dense_rank() over (order by project) as DR_Projects
from test
) a
或者,甚至更丑陋:
select * from
(select count(*) as Nodes from
(select node
from test
group by node) a
) a
inner join
(select count(*) as Projects from
(select project
from test
group by project) b
) b
on 1 = 1