Rumah > Soal Jawab > teks badan
Saya mempunyai 2 meja Permainan dan Perdagangan Saya menggunakan jumlah formula ini(EntryFee * Rake/(100 + Rake)*TotalEntry) dalam jadual Permainan untuk mendapatkan nilai
Saya menggunakan pertanyaan ini dalam kiraan jadual transaksi(id pengguna yang berbeza) untuk mendapatkan nilai
Sekarang saya ingin membahagikan nilai [jumlah(EntryFee * Rake/(100 + Rake)*TotalEntry)] dengan nilai [count(distinct UserID)]
Contohnya jumlah(Yuran Penyertaan * Rake/(100 + Rake)*TotalEntry) = 90 dan kiraan(ID Pengguna yang berbeza) = 3 Kemudian 90/3 =30 Bagaimanakah saya boleh melakukan ini dalam MYSQL
P粉2956161702024-03-31 09:37:42
CREATE TABLE Games (EntryFee INT, Rake INT, TotalEntry INT); CREATE TABLE Transaction1 (UserID VARCHAR(25)); INSERT INTO Games VALUES (30,16,150),(45,20,100),(15,5,50),(25,20,300),(10,8,270); INSERT INTO Transaction1 VALUES ('Daniel'),('David'),('John'),('Martha'); SELECT Games.EntryFee, Games.Rake, Games.TotalEntry, COUNT(distinct Transaction1.UserID) AS CountUser, (Games.EntryFee * Games.Rake / (100 + Games.Rake) * Games.TotalEntry / COUNT(distinct Transaction1.UserID)) AS Calculate FROM Games JOIN Transaction1 GROUP BY Games.EntryFee, Games.Rake, Games.TotalEntry;
Hasil:
+==========+======+============+===========+==============+ | EntryFee | Rake | TotalEntry | CountUser | Calculate | +==========+======+============+===========+==============+ | 10 | 8 | 270 | 4 | 50.00000000 | +----------+------+------------+-----------+--------------+ | 15 | 5 | 50 | 4 | 8.92857500 | +----------+------+------------+-----------+--------------+ | 25 | 20 | 300 | 4 | 312.50000000 | +----------+------+------------+-----------+--------------+ | 30 | 16 | 150 | 4 | 155.17242500 | +----------+------+------------+-----------+--------------+ | 45 | 20 | 100 | 4 | 187.50000000 | +----------+------+------------+-----------+--------------+
P粉4884647312024-03-31 00:53:56
SELECT ( SELECT sum(EntryFee * Rake/(100 + Rake)*TotalEntry) FROM Games )/( SELECT count(distinct UserID) FROM Transaction ) MyResult