ツイートのテキストやツイートをツイートしたユーザーのスクリーンネームなど、多くのTwitterツイートの情報を格納するテーブルがあります。ツイートにはハッシュタグ(#で始まる)が含まれています。特定のユーザーがツイートしたハッシュタグの数を数えたいと思います。
tweet_id | tweet_text | screen_name |
--------------------------------------------------------------------------------------------
1 | #hashtag1 #otherhashtag2 #hashtag3 some more text | tweeter_user_1 |
2 | some text #hashtag1 #hashtag4 more text | tweeter_user_2 |
3 | #hashtag5 #hashtag1 @not a hashtag some#nothashtag | tweeter_user_1 |
4 | #hashtag1 with more text | tweeter_user_3 |
5 | #otherhashtag2 #hashtag3,#hashtag4 more text | tweeter_user_1 |
tweeter_user_1のハッシュタグを数えると、期待する結果は8になります。tweeter_user_3のハッシュタグが必要な場合は、1が返されます。テーブル名がツイートであると仮定すると、どうすればよいですか。
私はこれを試しました:SELECT COUNT( * ) FROM tweets WHERE( LENGTH( REPLACE( tweet_text, '#%', '@') = 0 ) ) AND screen_name = 'tweeter_user_1'
しかしそれはうまくいきませんでした
tweeter_user_1の結果も9だったら嬉しいです:D