Summing scores from multiple SQLite tables -
Summing scores from multiple SQLite tables -
i have 4 tables follows:
board1
round nspair ewpair nspoints ewppoints 1 1 1 4 0 2 4 3 2 2 3 3 4 0 4
board2
round nspair ewpair nspoints ewppoints 1 2 2 2 2 2 1 4 2 2 3 4 1 2 2
board3
round nspair ewpair nspoints ewppoints 1 3 3 3 1 2 2 1 3 1 3 1 2 0 4
board4
round nspair ewpair nspoints ewppoints 1 4 4 0 4 2 3 2 3 1 3 2 3 3 1
i create sql query add together each pairs points like:
select sum nspoints board1, board2, board3, board4 nspair = 1
i tried various ways accomplish seem fall on when nspair not exist in board 4 above. looks relatively mutual task , there must right way it. help appreciated.
the right way handle single board
table board_number
column.
anyway, create view can handled table:
create view all_boards select * board1 union select * board2 union select * board3 union select * board4; ... select sum(nspoints) all_boards nspair = 1;
alternatively, combine tables dynamically:
select sum(nspoints) (select nspoints, nspair board1 union select nspoints, nspair board2 union select nspoints, nspair board3 union select nspoints, nspair board4) nspair = 1
sqlite
Comments
Post a Comment