SQL错误:无法将表中的布尔列与从另一个表获取的列名匹配

时间:2017-09-12 13:38:58

标签: mysql sql amazon-redshift

我有一个查询,它返回另一个表中布尔列的名称。 我需要返回所有具有相同列名= true的结果。

  

获取错误:WHERE的参数必须是boolean类型,而不是类型   性格变化

我理解这个问题,如何修改服务器的查询以将变量标识为列名?

查询:

WITH c2 AS(
WITH static_vertical_distribution AS (
 SELECT clean_url, UID, VBUSINESS, VENTERTAINMENT, VFASHION, VFOOD, VHOME, VLUXURY, VNEWS, VSPORTS, VTRAVEL FROM table2017_09_11 WHERE uid='XXXXX' UNION ALL 
 SELECT clean_url, UID, VBUSINESS, VENTERTAINMENT, VFASHION, VFOOD, VHOME, VLUXURY, VNEWS, VSPORTS, VTRAVEL FROM table2017_09_10 WHERE uid='XXXX' 
UNION ALL 

 SELECT clean_url, UID, VBUSINESS, VENTERTAINMENT, VFASHION, VFOOD, VHOME, VLUXURY, VNEWS, VSPORTS, VTRAVEL FROM table_2017_09_09 WHERE uid='XXXX'),

cte AS(
 select 'BUSINESS & TECHNOLOGY' as vertical, 'vbusiness' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vbusiness union all
 select 'ENTERTAINMENT' as vertical, 'ventertainment' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where ventertainment union all
 select 'FASHION & BEAUTY' as vertical, 'vfashion' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vfashion union all
 select 'FOOD & ENTERTAINING' as vertical, 'vfood' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vfood union all
 select 'HOME & DESIGN' as vertical, 'vhome' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vhome union all
 select 'LUXURY & DESIGN' as vertical, 'vluxury' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vluxury union all
 select 'NEWS' as vertical, 'vnews' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vnews union all
 select 'SPORTS & FITNESS' as vertical, 'vsports' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vsports union all
 select 'TRAVEL' as vertical, 'vtravel' as col, count(distinct clean_url) as vertical_count from static_vertical_distribution where vtravel)

**Select  vertical,col,vertical_count from cte Order by vertical_count DESC LIMIT 1**
)



WITH cte AS(
 Select clean_url FROM table2017_09_11 where 
(**Select c2.col from c2 c2**) UNION ALL  Select clean_url FROM table2017_09_10 where (**Select c2.col from c2 c2**) 
UNION ALL  Select clean_url FROM table2017_09_09 where (**Select c2.col from c2 c2**))
Select clean_url,count(clean_url) as count1 from cte GROUP BY clean_url ORDER by count1 DESC LIMIT 10;

0 个答案:

没有答案