議論の重複を減らすことができる方法はありますか? たとえば、timepattern は 4 回繰り返され、大きなクエリを追跡するのが難しくなります。
sql = ( "SELECT IFNULL(b.inviters/COUNT(DISTINCT c.id),0), "
" FROM_UNIXTIME(c.registered_at, %s) "
"FROM ( SELECT COUNT(1) AS inviters, joindate "
" FROM "
" ( SELECT DISTINCT(y.id) AS inviters, "
" FROM_UNIXTIME(y.registered_at, %s) AS joindate "
" FROM user_invites z "
" INNER JOIN users y ON y.id = z.inviter_id "
" WHERE z.created_at >= %s "
" ) a "
" GROUP BY a.joindate "
" ) b "
"INNER JOIN users c ON FROM_UNIXTIME(c.registered_at, %s) = b.joindate "
"WHERE c.registered_at BETWEEN %s AND %s "
"GROUP BY FROM_UNIXTIME(c.registered_at, %s) " )
args = ( timepattern, timepattern, datestart_int, timepattern,
datestart_int, dateend_int, timepattern )
cursor.execut(sql, args)
data = list(cursor.fetchall())
cursor.close()
connection.close()