0

I have a grails application with a mysql database as the datasource. The mysql database is created and maintained by a third party. One of the tables 'visitinfo' contains 2 columns consisting of the 'userid' and 'logindatetime'.

userid is of type TEXT and logindatetime is of type 'datetime'.

In order to access the above table 'visitinfo', I have created a domain class 'VisitInfo' and mapped it to the mysql database table by which my grails application can easily store as well as retrieve data from the database.

On one of the pages, I am required to show visitor information for the last 30 days. So basically I am looking out for a solution to get number of visitors per day for the last 30 days. Something like this:

21-Jan-2012 ------ 36
22-Jan-2012 ------ 85
23-Jan-2012 ------ 115
24-Jan-2012 ------ 236
etc.

Also please note, that if a userid 'williamp' has 2 entries on a particular day, it should be counted as 2. So, am not looking out for uniqueness of users.

Any help will be appreciated.

4

3 に答える 3

0

countBygormメソッドを使用します。

numLogins=VisitInfo.countByReleaseDateBetween(startOfDay,endOfDay)

これは、過去30日間のそれぞれについて2つの日付オブジェクトを計算するループ内にある必要があります。startOfDayには00:00:00:00の時間値が必要であり、endOfDayには23:59:00:00の時間値が必要です。

于 2013-01-24T13:56:49.870 に答える
0

私はグレイルについて全く知りません。目的の結果を取得するための MySQL クエリは次のとおりです。

SELECT DATE_FORMAT(logindatetime,'%d-%m-%Y') dt
     , COUNT(*) total
  FROM visitinfo
 GROUP 
    BY dt;
于 2013-01-24T13:45:59.333 に答える
0

要件に合わせて hql クエリに従うことをお勧めします

VisitInfo.executeQuery("select logindatetime, count(*) from VisitInfo group by logindatetime") 
于 2013-01-24T13:45:20.487 に答える