tailieunhanh - Joe Celko s SQL for Smarties - Advanced SQL Programming P62

Joe Celko s SQL for Smarties - Advanced SQL Programming P62. In the SQL database community, Joe Celko is a well-known columnist and purveyor of valuable insights. In Joe Celko's SQL for Smarties: Advanced SQL Programming, he picks up where basic SQL training and experience leaves many database professionals and offers tips, techniques, and explanations that help readers extend their capabilities to top-tier SQL programming. Although Celko denies that the book is about database theory, he nevertheless alludes to theory often to buttress his practical points. This title is not for novices, as the author points out. Instead, its intended. | 582 CHAPTER 25 ARRAYS IN SQL j INTEGER NOT NULL CHECK j 0 CHECK SELECT MAX i FROM MyMatrix SELECT COUNT i FROM MyMatrix CHECK SELECT MAX j FROM MyMatrix SELECT COUNT j FROM MyMatrix The constraints see that the subscripts of each element are within proper range. I am starting my subscripts at one but a little change in the logic would allow any value. Matrix Equality This test for matrix equality is from the article SQL Matrix Processing Mrdalj Vujovic and Jovanovic 1996 . Two matrices are equal if their cardinalities and the cardinality of the their intersection are all equal. SELECT COUNT FROM MatrixA UNION SELECT COUNT FROM MatrixB UNION SELECT COUNT FROM MatrixA AS A MatrixB AS B WHERE AND AND You have to decide how to use this query in your context. If it returns one number they are the same otherwise they are different. Matrix Addition Matrix addition and subtraction are possible only between matrices of the same dimensions. The obvious way to do the addition is simply SELECT AS total FROM MatrixA AS A MatrixB AS B WHERE AND But properly you ought to add some checking to be sure the matrices match. We can assume that both start numbering subscripts with either one or zero. Matrix Operations in SQL 583 SELECT AS total FROM MatrixA AS A MatrixB AS B WHERE AND AND SELECT COUNT FROM MatrixA SELECT COUNT FROM MatrixB AND SELECT MAX i FROM MatrixA SELECT MAX i FROM MatrixB AND SELECT MAX j FROM MatrixA SELECT MAX j FROM MatrixB Likewise to make the addition permanent you can use the same basic query in an UPDATE statement UPDATE MatrixA SET element element SELECT element FROM MatrixB WHERE AND WHERE SELECT COUNT FROM MatrixA SELECT COUNT FROM MatrixB AND SELECT MAX i FROM MatrixA SELECT MAX i FROM MatrixB AND SELECT MAX j FROM MatrixA SELECT MAX j FROM MatrixB Matrix .