MySQL を使用して Rails ですべての異なるユーザーの最新の訪問を確認する方法
各異なるユーザーの最新の訪問時間を取得したい場合あなたのデータベースに。 ActiveRecord クエリで DISTINCT ON 関数を使用しようとしていますが、SQL 構文エラーが発生しました。
DISTINCT ON 関数は PostgreSQL に固有であり、MySQL はサポートしていません。代わりに、GROUP BY 関数と MAX 関数を使用すると、目的の結果を得ることができます。
クエリを次のように変更します。
<code class="ruby">Event.group(:user_id).maximum(:time)</code>
このクエリは、user_id でイベントをグループ化し、最大値を返します。各グループの時間値。これにより、各固有のユーザーの最新の訪問時間が得られます。
出力:
結果の出力はハッシュになり、キーは user_id と値になります。は、Time オブジェクトとしての最新の訪問時刻です:
<code class="ruby">{ 21 => Tue, 18 Dec 2018 11:15:24 UTC +00:00, 23 => Thu, 20 Dec 2018 06:42:10 UTC +00:00 }</code>
strftime を使用して、好みに合わせて時間値をフォーマットできることに注意してください。
以上がMySQL を使用して Rails で各一意のユーザーの最新の訪問時間を取得するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

todropaviewinmysql、 "dropviewifexistsview_name;" andtomodifyaviewを使用して、 "createorreplaceviewview_nameasselect ..."を使用します

mysqlviewscanefectiveativeativeizedesignpatternslikeadapter、decorator、factory、andobserver.1)adapterpatternadaptsdatafromdifferenttablesintoaunifiedview.2)decoratorpatternenhancesdatawithedfieldsfieldsiffieldsiffieldsiffiedを

viewsinmysqlarebenefentialforsimprifiningcomplexqueries、拡張セキュリティ、ダタコンシーニング、および最適化されたパフォーマンスを保証する1)itsmplifyififycomplexqueriesbyencapsulsingthemintoreusableviews.2)viewsencurationecuritybycontrollingcescesces.3)

to CreateAsimpleviewinmysql、usethecreateviewstatement.1)DefinetheTheTheThecreateview_nameas.2)SpecifyTheSelectStatementtatementtatementtatementtatementtatementtatementedeSireddata.3)

tocleateusersinmysql、usethecreateuserstatement.1)foralocaluser:createUser'localuser '@' localhost'identifidedifiedifiedified 'securepassword';

mysqlviewshavelimitations:1)supportallsqloperations、制限、dataManipulationswithjoinsorubqueries.2)それらは、特にパフォーマンス、特にパルフェクソルラージャターセット

reperusermanmanagementInmysqliscialforenhancingsecurationsinginuring databaseaperation.1)usecreateusertoaddusers、指定connectionsourcewith@'localhost'or@'% '。

mysqldoes notimposeahardlimitontriggers、しかしpracticalfactorsdeTerminetheireffectiveuse:1)serverconufigurationStriggermanagement; 2)complentiggersincreaseSystemload;


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール
