mariano / node-db-mysql

MySQL database bindings for Node.js
http://nodejsdb.org
150 stars 30 forks source link

GroupBy support #40

Open markwillis82 opened 13 years ago

markwillis82 commented 13 years ago

Hi,

I can't seem to find in the documentation (code.google.com/apis/maps/documentation/javascript/reference.html) how to perform a groupby (without running a raw statement) is this something planned for future release?

tomasm- commented 12 years ago

You can do GROUP BY (or anything else arbitrary) with the .add() chain:

db.query().select("COUNT(*)").from("messages").add(" GROUP BY user_id").execute();

Just make sure you put a space BEFORE the GROUP BY, as it doesn't do it for you (it will look like "FROM messagesGROUP BY...")

tomasm- commented 12 years ago

NOT to confuse "add()" with "and()".