56,678
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([aid] int,[type] int,[value] int)
Insert #T
select 1,1,12 union all
select 1,1,13 union all
select 1,2,6 union all
select 2,1,0 union all
select 2,2,0 union all
select 3,1,15
GO
if not object_id(N'Tempdb..#article') is null
drop table #article
Go
Create table #article([aid] INT,title NVARCHAR(100))
Insert #article
select 1,'文章1' UNION
SELECT 2,'文章2' UNION
SELECT 3,'文章3'
Go
--测试数据结束
SELECT DISTINCT a.*
FROM #article a
JOIN #T b ON b.aid = a.aid
JOIN #T c ON c.aid = a.aid
WHERE b.type = 1
AND ','+'1,12,13'+',' LIKE '%,'+RTRIM(b.value) + '%,' --这里改成这样的,下边那个也是
AND c.type = 2
AND c.value = 6; --去读职业为6的 ,同上边一样
[/quote]
谢谢,结帖--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([aid] int,[type] int,[value] int)
Insert #T
select 1,1,12 union all
select 1,1,13 union all
select 1,2,6 union all
select 2,1,0 union all
select 2,2,0 union all
select 3,1,15
GO
if not object_id(N'Tempdb..#article') is null
drop table #article
Go
Create table #article([aid] INT,title NVARCHAR(100))
Insert #article
select 1,'文章1' UNION
SELECT 2,'文章2' UNION
SELECT 3,'文章3'
Go
--测试数据结束
SELECT DISTINCT a.*
FROM #article a
JOIN #T b ON b.aid = a.aid
JOIN #T c ON c.aid = a.aid
WHERE b.type = 1
AND ','+'1,12,13'+',' LIKE '%,'+RTRIM(b.value) + '%,' --这里改成这样的,下边那个也是
AND c.type = 2
AND c.value = 6; --去读职业为6的 ,同上边一样
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([aid] int,[type] int,[value] int)
Insert #T
select 1,1,12 union all
select 1,1,13 union all
select 1,2,6 union all
select 2,1,0 union all
select 2,2,0 union all
select 3,1,15
GO
if not object_id(N'Tempdb..#article') is null
drop table #article
Go
Create table #article([aid] INT,title NVARCHAR(100))
Insert #article
select 1,'文章1' UNION
SELECT 2,'文章2' UNION
SELECT 3,'文章3'
Go
--测试数据结束
SELECT a.*
FROM #article a
JOIN #T b ON b.aid = a.aid
JOIN #T c ON c.aid = a.aid
WHERE b.type = 1
AND b.value = 12 --读取兴趣为12的,这个12应该是传入进来的,根据当前访问人
AND c.type = 2
AND c.value = 6; --去读职业为6的 ,同上边一样