**

select … from … where … group by … order by … limit …

注意:
函数使用

  1. select 后普通字段不能加别名

eg: select name as n from tableName

  1. Elasticsearch 中分词字段(text 类型)不能做函数操作

    trim(text..) keyword date long(number)

  2. 不支持having 操作

  3. 别名需字母开头,只能包含数字、字母、下划线
  4. 使用group by之后,select 的字段只能是group by 后的字段或 所有字段的聚合函数

eg: select DF_ID,max(DF_INSERT_TIME) as mx from tfp12345 group by DF_ID

  1. where后不可使用别名


查询字段

  1. 不支持没有指定类型的字段的操作
  2. 不支持嵌套类型字段的操作
  3. 不支持常量字段

eg: select 1 from table

**

**

select test01,test02 from test_yhq_date where test02 = ‘A’ and test01 = 2

**

select test01,test02 from test_yhq_date where test02 = ‘A’ or test01 = 2

**

select max(test01) as max from test_yhq_date

**

select min(test01) as max from test_yhq_date

**

elect avg(test01) as avg from test_yhq_date

**

select count(test01) as count from test_yhq_date

**

select sum(test01) as count from test_yhq_date

**

SELECT substring(‘test02’,0,2) as aa FROM test_yhq_date

**

case when xx then xx else xx end
select case when test02 = ‘A’ then ‘aaa’ else test02 end test from test_yhq_date

**

条件匹配目前仅支持字符串类型,不支持number类型
格式:if(xx = .. xx, xx, xx)
select test01,if(test02 = ‘A’,’AA’,’BB’) as test,test02 from test_yhq_date

**

SELECT test01 FROM test_yhq_date where test01 in (1,2,3)

**

select case when test01 between 0 and 3 then ‘aaa’ else test01 end test from test_yhq_date

**

后台会转为wildcard模糊匹配,查询text类型时需要注意分词类型
select origin,title from nmgzy where title like “%普通%” limit 5

**

SELECT test02,test03 FROM test_yhq_date where test03 is not null

**

SELECT trim(test02) as trim FROM test_yhq_date

**

使用:concat_ws(连接符,参数1,参数2)
eg: concat_ws(‘-‘,’a’,’b’) a-b
SELECT concat_ws(‘-‘,test01,test02) as aa FROM test_yhq_date

**

对number类型 5 5.0
SELECT floor(test01) as aa FROM test_yhq_date

**

**

match查询会先将查询语句进行分词,只要数据满足其中一部分即视为命中. 即检索 ‘880 Holmes Lane’, 结果语句中只要包含3词中对任意一个就会返回
eg:
select address from bank where address= matchQuery(‘880 Holmes Lane’)
select title from nmgzy where title= matchQuery(‘高等’) limit 3
select app_name from tfp12345 where app_name= matchQuery(‘债券’)

**

会对查询语句进行分词,在查询text的时候,结果需要包含所有查询的关键词,单先后顺序不要求。 ‘q=’ 这个是固定写法
eg:
select address from bank where q= query(‘address:880 Holmes Lane’) limit 3
select title from nmgzy where q= query(‘title:高’)
select app_name from tfp12345 where q= query(‘app_name:债券’)

**

可指定浮点数,该值作为匹配了查询关键词的相似度分(权重),默认为1.0
eg:
select address from bank where address= score(matchQuery(‘Lane’),100) or address= score(matchQuery(‘Street’),0.5) order by _score desc limit 3;
select title from nmgzy where title= score(matchQuery(‘普通’),100) or title= score(matchQuery(‘高等’),0.5)
select app_name from tfp12345 where app_name= score(matchQuery(‘债券’),100) or app_name= score(matchQuery(‘检测’),0.5)

**

使用通配符进行查询,其中?代表任意一个字符 代表任意的一个或多个字符
eg:
select address from bank where address= wildcardQuery(‘l
e’) order by _score desc limit 3
select title from nmgzy where title= wildcardQuery(‘‘) limit 3
select app_name from tfp12345 where app_name= wildcardQuery(‘‘)

**

会对查询语句进行分词,在查询text的时候,结果需要包含所有查询的关键词,且要求顺序相同且必须是连续的。
eg:
select address from bank where address= matchPhrase(‘671 Bristol Street’) order by _score desc limit 3
select title from nmgzy where title= matchPhrase(‘普通’) limit 5
select app_name from tfp12345 where app_name= matchPhrase(‘公告’)