我正在尝试 运行 sql 中的查询,我将字段更改为小写以使其一致并对不同字段求和

I am trying to run a query in sql where I change the fields to lowercase to make it consistent and sum the differetn fields

我有一个字段 evar4,它有站点搜索,文本在不同的情况下导致搜索到的同一个词有两个不同的行, 例如

evar4  searches
games   3236
Games    564

我想将所有 evar4 转换为小写字段并为所有相同的术语显示单个值,即,

e.g.
evar4  searches
games   3800

我已将字段转换为小写,但我不确定如何在 sql 查询中对这些字段求和并只显示同一单词的一行。

Select lcase(evar4), count (evar4) as searches from adobe_hits
where (date(date_time) between '2019-01-01' and '2019-01-31')
and post_prop46 like ('www:')
and exclude_hit like '0'
and hit_source not in (5,7,8,9)
group by evar4
order by searches desc;

sample result: 

Original Result:
evar4                 searches
games                   3236
recently played games   1326
mahjongg solitaire  633
Games                   564

Result after lcase: 
lcase(evar4)            searches
games                   3236
recently played games   1326
mahjongg solitaire  633
games                   564

desired result: 
lcase(evar4)            searches
games                   3800
recently played games   1326
mahjongg solitaire  633

您需要按字段的小写形式分组。

Select lcase(evar4), count (evar4) as searches from adobe_hits
where (date(date_time) between '2019-01-01' and '2019-01-31')
and post_prop46 like ('www:')
and exclude_hit like '0'
and hit_source not in (5,7,8,9)
group by lcase(evar4)
order by searches desc;

如果您为表达式分配别名,则可以按该别名进行分组。

Select lcase(evar4) as l_evar4, count (evar4) as searches from adobe_hits
where (date(date_time) between '2019-01-01' and '2019-01-31')
and post_prop46 like ('www:')
and exclude_hit like '0'
and hit_source not in (5,7,8,9)
group by l_evar4
order by searches desc;

另一种避免必须首先执行此操作的解决方案是声明该列使用不区分大小写的排序规则。那么所有的比较,包括分组,都会忽略大小写。