SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
create table del_test_oper_2_0 (client_pin varchar(25), value_day varchar(25), turnover int); INSERT ALL INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-06-02', 2000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-06-03', 3000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-06-04', 1000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-06-05', 10000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-06-24', 20000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-06-30', 35000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-07-06', 3500) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-07-08', 10500) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-07-09', 5000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-07-15', 100000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-07-21', 85000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ256','2019-07-27', 95000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ345','2019-07-01', 1500) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ345','2019-07-02', 2500) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ345','2019-07-20', 4000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ345','2019-07-22', 65000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ345','2019-07-23', 25000) INTO del_test_oper_2_0(client_pin,value_day , turnover ) values ('AQ345','2019-07-28', 15000) SELECT * FROM DUAL; COMMIT; select * from del_test_oper_2_0; with q1 as ( ---сумма транзакций в день на клиента select VALUE_DAY ,CLIENT_PIN ,sum (TURNOVER) as sum_TURN_day from del_test_oper_2_0 group by VALUE_DAY ,CLIENT_PIN ) ,q2 as ( select distinct VALUE_DAY ,CLIENT_PIN ,SUM_TURN_DAY ,SUM_TURN_DAY * 0.05 as sum_cashbak ,case when SUM_TURN_DAY * 0.05 >=1000 then 1000 else SUM_TURN_DAY * 0.05 end as cashback_sum_day from q1 order by VALUE_DAY ) ,q3 as ( ---Сумма тран и кешбека с ограничениями и без на клиента в месяц select LAST_DAY(TO_DATE(VALUE_DAY, 'yyyy.mm.dd')) AS VALUE_mnt ,CLIENT_PIN ,sum(SUM_TURN_DAY) as SUM_TURN_mnt ,sum(SUM_CASHBAK) as SUM_CASHBAK_mnt ,sum(cashback_sum_day) as cashback_sum_mnt from q2 group by LAST_DAY(TO_DATE(VALUE_DAY, 'yyyy.mm.dd')) ,CLIENT_PIN ) ,q4 as (--- Общая сумма транзакций и рассчитанный кешбек на месяц по всем клиентам select LAST_DAY(TO_DATE(a.VALUE_DAY, 'yyyy.mm.dd')) AS VALUE_mnt ,sum(a.SUM_TURN_DAY) as SUM_TURN_mnt ,sum(a.SUM_CASHBAK) as SUM_CASHBAK_mnt ,sum(a.cashback_sum_day) as cashback_sum_mnt from q2 a --left join q3 b on a.CLIENT_PIN=b.CLIENT_PIN group by LAST_DAY(TO_DATE(VALUE_DAY, 'yyyy.mm.dd')) ) select distinct a.VALUE_DAY ,a.CLIENT_PIN ,a.CASHBACK_SUM_DAY from q2 a ;
SQL
Server:
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
MariaDB 11.5
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear