SQL语言以及MySQL基础

1.基本句型(顺序有关)

SELETE 列名称
FROM 表名称
WHERE 条件(列 运算符 值)
GROUPBY 分组
HAVING 由于WHERE中不能出现合计函数,用HAVING替代
UNION 合并结果集 ORDERBY 列 DISC(逆序)

2.1.将查询到的数据导入到数组中(大量数据)

    String fsql = "select DATE_FORMAT(t.data_date,'%H'),t.index_value "
           +"from ps_stat_index_hour t  "
           +"where t.index_id=1 and t.equipment_id=1  and DATE_FORMAT(t.data_date,'%Y-%m-%d')='2016-08-17' "
           +"order by t.data_date"
    
    Query query1 = em.createNativeQuery(fsql);
    List res1 = query1.getResultList();

    Map<String, Object> dataStore = new HashMap<>();
    for (Object object : res1) {
        Object[] rec = (Object[]) object;
        dataStore.put(Integer.valueOf(rec[0].toString()) + "", rec[1]);
    }
    JSONArray linedata = new JSONArray();
    for (int i = 0; i < 24; i++) {
        linedata.add(dataStore.get(i + ""));
    }
    return linedata.toString();

 

posted @ 2016-08-17 17:08  骑驴的是郭襄  阅读(127)  评论(0编辑  收藏  举报