0

だから私は次のクエリを持っています:

public function findByDateCreated($date){
        $select = $this->select();
        $select->where('dtcreated = ?', $date);
        $select->group('date');
        $rows = $this->fetchAll($select);
        if(count($rows) > 0){
            return $rows[0];
        }else{
            return false;
        }
    }

エラーがスローされます:

500: SQLSTATE[42703]: Undefined column: 7 ERROR: column "date" does not exist LINE 1: ...E (dtcreated = '2012-10-17 14:26:41.575479') GROUP BY "date" ^

私の質問は:

次のように日付でグループ化するにはどうすればよいですか。

17-10-2012
One item
two item
three item

16-10-2012
oneitem
twoitem
threeitem

等々?

これがどのように役立つかわかりませんが、

create table users_notifications(
    id  int primary key default nextval('users_notifications_id_seq') not null,
    userid int not null references users(id),
    itemid int not null,
    itemtype varchar(75),
    dtcreated timestamp not null default now(),
    dtupdated timestamp default now(),
    message text,
    flag boolean,
    flagnew boolean
);

テーブルはこんな感じ。

4

1 に答える 1

0

エラーは、という列dateがないため、それでグループ化できないためです。

これを試して:

$select->group(new Zend_Db_Expr("date_trunc('hour', dtcreated)"));

これにより、すべての日時が年、月、日のコンポーネントだけに切り捨てられ、結果の値でグループ化されます。

于 2012-10-18T15:38:22.193 に答える