SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table tbl ( _ustr int, _date datetime, _metr double ); insert into tbl values (1, '2022-01-01 05:00:01', 1.01), (2, '2022-01-01 05:00:01', 2.10), (3, '2022-01-01 05:00:01', 3.04), (4, '2022-01-01 05:00:01', 1.41), (5, '2022-01-01 05:00:01', 2.60), (1, '2022-01-02 01:01:01', 3.01), (2, '2022-01-03 03:12:01', 6.14), (3, '2022-01-04 05:13:01', 1.01), (4, '2022-01-05 03:24:01', 5.51), (5, '2022-01-06 02:35:01', 3.74); select _date, sum(case when _ustr = 1 then _metr else 0 end) _ustr_1, sum(case when _ustr = 2 then _metr else 0 end) _ustr_3, sum(case when _ustr = 3 then _metr else 0 end) _ustr_3, sum(case when _ustr = 4 then _metr else 0 end) _ustr_4, sum(case when _ustr = 5 then _metr else 0 end) _ustr_5 from tbl group by _date;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear