sql - OrientDB - Group by date query -


i'm trying execute query in orientdb number of posts per day. however, group query failing, , fail see i'm doing wrong.

i have database filled 3 posts, different date.

this query:

select     dateposted.format("dd-mm-yyyy") day, count(*)     post group     day 

however, doesn't work. expect retrieve structure number of posts per day, retrieves 1 result:

[#-2:1{count:3} v0] 

any suggestions?

i created structure , think that's similar yours:

create class post  create property post.dateposted date  insert post (dateposted) values ('2016-01-25') insert post (dateposted) values ('2016-01-28') insert post (dateposted) values ('2016-01-25') insert post (dateposted) values ('2016-02-04') 

these options retrieve results want:

first query:

select day, count(*) posts (select dateposted.format('yyyy-mm-dd') day post)  group day 

output:

----+------+----------+----- #   |@class|day       |posts ----+------+----------+----- 0   |null  |2016-01-25|2 1   |null  |2016-01-28|1 2   |null  |2016-02-04|1 ----+------+----------+----- 

second query:

select dateposted.format('yyyy-mm-dd'), count(*) posts post group dateposted 

output:

----+------+----------+----- #   |@class|dateposted|posts ----+------+----------+----- 0   |null  |2016-01-25|2 1   |null  |2016-01-28|1 2   |null  |2016-02-04|1 ----+------+----------+----- 

hope helps

edited

here's example in java:

java code:

private static string remote = "remote:localhost/";     public static void main(string[] args) {         string dbname = "dbname";         string path = remote + dbname;         oserveradmin serveradmin;         try {             serveradmin = new oserveradmin(path).connect("root", "root");             if (serveradmin.existsdatabase()) { // if db exists                 system.out.println("database '" + dbname + "' exists");                 odatabasedocumenttx db = new odatabasedocumenttx(path);                 db.open("root", "root");                 iterable<odocument> results = db                     .command(new osqlsynchquery<odocument>(                             "select day, count(*) posts (select dateposted.format('yyyy-mm-dd') day post) group day"))                     .execute();                 (odocument result : results) {                     system.out.println("day: " + result.field("day") + "   posts: " + result.field("posts"));                 }                 db.close();             }             else {                 serveradmin.createdatabase(dbname, "document", "plocal");                 system.out.println("database " + dbname + " created");             }             serveradmin.close();         } catch (ioexception e) {             e.printstacktrace();         }     } 

output:

day: 2016-01-25   posts: 2 day: 2016-01-28   posts: 1 day: 2016-02-04   posts: 1 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -