CREATE TABLE IF NOT EXISTS talkers (jid varchar, nick varchar, room varchar, words int, me int, sentences int);
-- @create_index1
CREATE INDEX IF NOT EXISTS talkersidx ON talkers (jid, room);
-- @create_index2
CREATE INDEX IF NOT EXISTS words_idx ON talkers (words);
-- @test_nick
SELECT COUNT(*) FROM talkers WHERE nick=@nick AND room=@room;
-- @test_jid
SELECT COUNT(*) FROM talkers WHERE jid=@jid AND room=@room;
-- @update_by_nick
UPDATE talkers SET words=words+@words, sentences=sentences+@se, me=me+@me WHERE nick=@nick AND room=@room;
-- @update_by_jid
UPDATE talkers SET words=words+@words, sentences=sentences+@se, me=me+@me WHERE jid=@jid AND room=@room;
-- @insert_new
INSERT INTO talkers (jid, nick, room, words, me, sentences) VALUES;
-- @select_talkers
SELECT nick, words, me, sentences FROM talkers WHERE room=@room AND nick LIKE @nick ORDER BY words DESC, sentences ASC LIMIT @limit;
