Sql server SQL Server中的矩阵输出类型
我需要获得订阅频道的客户数Sql server SQL Server中的矩阵输出类型,sql-server,Sql Server,我需要获得订阅频道的客户数 Where channel = telugu and channel = hindi Where channel = telugu and channel = English Where channel = hindi and channel = English 我想我知道你想要什么。。。客户可以有多个渠道,您有兴趣统计拥有特定渠道组合的客户。 如果这是正确的,并且您的组合都具有相同数量的元素,那么您可以使用如下内容 IF OBJECT_ID('tempdb.
Where channel = telugu and channel = hindi
Where channel = telugu and channel = English
Where channel = hindi and channel = English
我想我知道你想要什么。。。客户可以有多个渠道,您有兴趣统计拥有特定渠道组合的客户。 如果这是正确的,并且您的组合都具有相同数量的元素,那么您可以使用如下内容
IF OBJECT_ID('tempdb..#channel_pairs', 'U') IS NOT NULL
BEGIN DROP TABLE #channel_pairs; END;
CREATE TABLE #channel_pairs (
c1 varchar(20) NOT NULL,
c2 varchar(20) NOT null
);
INSERT #channel_pairs (c1, c2) VALUES ('telugu', 'hindi'), ('telugu', 'English'), ('hindi', 'English');
SELECT
channel_pair = cp.c1 + ', ' + cp.c2,
cp_count = COUNT(1)
FROM
dbo.customer_channel cc1
JOIN dbo.customer_channel cc2
ON cc1.customer_id = cc2.customer_id
JOIN #channel_pairs cp
ON cc1.channel = cp.c1
AND cc2.channel = cp.c2;
你的WHERE子句不起作用。channel=telugu和channel=hindi的位置将不匹配。你可能想要一个手术室