19个brand,让我给出2个或是3个brand任意组合的不同的match results!感觉脑细胞浪费在这上面真的不值!😭
19个brand,让我给出2个或是3个brand任意组合的不同的match results!感觉脑细胞浪费在这上面真的不值!😭
下面这段是SQL做的,11个brands找出所有的任意组合。
SELECT TOP (1048576)
n = ISNULL(CONVERT(integer, ROW_NUMBER() OVER (ORDER BY (SELECT NULL))), 0)
INTO #NUMBERS
FROM sys.columns AS c
CROSS JOIN sys.columns AS c2
CROSS JOIN sys.columns AS c3;
CREATE UNIQUE CLUSTERED INDEX cuq
ON #NUMBERS (n)
WITH (MAXDOP = 1, SORT_IN_TEMPDB = ON);
DECLARE @BRANDS AS TABLE
(
item_id tinyint IDENTITY(1,1) PRIMARY KEY NONCLUSTERED,
item nvarchar(500) NOT NULL,
bit_value AS
CONVERT
(
integer,
POWER(2, item_id - 1)
)
PERSISTED UNIQUE CLUSTERED
);
INSERT @BRANDS
(item)
VALUES
(N'brand_1'),
(N'brand_2'),
(N'brand_3'),
(N'brand_4'),
(N'brand_5'),
(N'brand_6'),
(N'brand_7'),
(N'brand_8'),
(N'brand_9'),
(N'brand_10'),
(N'brand_11');
-- Maximum integer we need
-- for all combinations of 'n' bits
DECLARE
@max integer =
POWER(2,
(
SELECT COUNT(*)
FROM @BRANDS AS s
)
) - 1;
SELECT
combination =
STUFF
(
(
-- Choose items where the bit is set
-- and concatenate all matches
SELECT ',' + s.item
FROM @BRANDS AS s
WHERE
n.n & s.bit_value = s.bit_value
ORDER BY
s.bit_value
FOR XML
PATH (''),
TYPE
).value('(./text())[1]', 'varchar(8000)'), 1, 1, ''
)
-- A standard numbers table
-- (single column, integers from 1 to 1048576, indexed)
INTO #COMBINATIONS
FROM #NUMBERS AS N
WHERE
N.n BETWEEN 1 AND @max;
SELECT COMBINATION
FROM #COMBINATIONS
WHERE (***(COMBINATION) - ***(REPLACE(COMBINATION,',','')) + 1) = 2
ORDER BY COMBINATION
👍
完全看不懂,总统大臣和大壮任意组合都不会出结果的。
让他们三个排排队,然后拍照,看看能排出多少张照片来?😆
for (let i=0; i<brands.length; i++) {
for(let j=0; j<brands.length; j++){
if(i==j) continue;
console.log(brands[i], brands[j])
}
}
for (let i=0; i<brands.length; i++) {
for(let j=0; j<brands.length; j++){
if(i==j) continue;
for(let k=0; k<brands.length; k++){
if(j==k) continue;
console.log(brands[i], brands[j], brands[k]);
}
}
}
厉害,厉害!😄 早知道就请你一起做web了!
过奖, SQL 是我的短板。20 年的逻辑,没被给机会搞 SQL
不懂你到专业。听上去象拌调料,里面放几种调味品的问题。
做Sales Marketig的人多半是忽悠。
我数学不好,这是排列组合,但是要用程序做,还要和我做的数据结合起来。
不过好在天下聪明人太多了,我刚才Google到人家写的程序,至少把排列组合做出来了。😄
我们公司的sales真的很忽悠,他们自己都不知道自己要干什么。