sql - Sum of similiar columns for each row -


i have table below

doctor_id    forename surname email           ...  1           jon      doe     jon@doe.com     ...  2           john     dove    john@dove.com   ...  3           jane     dane    jane@dane.com   ...  4           foo      bar     foo@bar.com     ...  5           bar      foo     bar@foo.com     ... 

please consider table has 10 more columns.

i have set of data (forename = "jon", surname="doe", email="foo@bar.com", etc.)

i want check each row number of columns have same value columns in set of data

doctor_id    forename surname email           ...   similiarities  1           jon      doe     jon@doe.com     ...   2  2           john     dove    john@dove.com   ...   0  3           jane     dane    jane@dane.com   ...   0  4           foo      bar     foo@bar.com     ...   1  5           bar      foo     bar@foo.com     ...   0 

and choose rows number of similiarities greater 3.

does want?

select t.*,        ((case when forename = 'jon' 1 else 0 end) +         (case when surname = 'doe' 1 else 0 end) +         (case when email = 'foo@bar.com' 1 else 0 end)        ) similarities t; 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -