在SQL中使用generate_series

时间:2017-03-15 05:57:17

标签: sql postgresql

我想创建一个包含1 1 1 2 2 2 3 3 3 4 4 4 5 5 5的列...一直到500 500 500.我被告知尝试使用generate_series,但还没有能够找到解决方案。

1 个答案:

答案 0 :(得分:1)

由于@FormUrlEncoded @POST(GlobalVariables.LOGIN_URL) void Login(@Field("email") String key, @Field("password") String value, Callback<Response> callback); getService().Login(email, password, new MyCallback<Response>(context, true, null) { @Override public void failure(RetrofitError arg0) { // TODO Auto-generated method stub UtilitySingleton.dismissDialog((BaseActivity<?>) context); System.out.println(arg0.getResponse()); } @Override public void success(Response arg0, Response arg1) { String result = null; StringBuilder sb = null; InputStream is = null; try { is = arg1.getBody().in(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); result = sb.toString(); System.out.println("Result :: " + result); } } catch (Exception e) { e.printStackTrace(); } } });

而假设Postgres
generate_series()

第一次调用select i from generate_series(1,500) as t(i) cross join generate_series(1,3) order by i; 会生成1到500之间的数字,然后交叉连接会使每行三倍。