Home>

I want to calculate the winning percentage for each ID from the data

** Please write your question in detail here.
** **

import sqlite3
filepath = "test2.sqlite"
conn = sqlite3.connect (filepath)
cur = conn.cursor ()
cur.execute ("DROP TABLE IF EXISTS items")
cur.execute ("" "CREATE TABLE items ("" "
id PRIMARY KEY,
time INTEGER
id2 INTEGER,
result INTEGER
) "" ")
conn.commit ()

cur = conn.cursor ()
data = [(1,2020-06-19 12:00,1,1),
(1,2020-08-19 13:00,2,1),
(1,2020-08-19 13:00,2,0),
(3,2020-08-23,14: 00,1,0),
(2,2020-08-23,14: 00,1,0),
(2,2020-08-23,14: 00,1,1),
(1,2020-08-23,14: 00,1,0),
(3,2020-08-23,15: 00,2,1)]

Win rate when 1 wins and 0 loses in Result
I want to calculate using SQL for each ID.

SQL + python