mysql: find newest non null values -
I have a huge table with 100 fields. Each line is timestamp, I want to find the latest non-empty values for all the columns. I am using MySql 5.6 InnoDB
like
CREATE TABLE Tester (pub_id int, pub_name varchar (20), Pbbt varchar (20), country varchar (20) Am no_of_branch varchar (20), estd datetime); Insert the tester (pub_id, pub_name, pubault, country, estd) values (1, 'A', 'Akswaijh' Absiti ',' A ',' 1 9 7l-0l-0l 00:00:01 '); (2, 'A', 'X', '', 'A', '71 71-01-01 00:00:01'), (3, 'A', 'X', 'ABC 1' 'B', '1972-01-01 00:00:01'), (4, 'A', 'Expose', '', 'A', '1973-01-01 00:00: 01 '), (5,' A ',' X ',' ABCT 2 ',' ',' 1974-01-01 00:00:01 '), (6,' B ',' LMN ' 'Abcity', 'a', '1974-01 -01 00:00:01'), (7, 'b', 'exay', '', 'a', '1 975-01-01 00 : 00, 01 '), (8,' b ',' sdf ',' abc1 ',' b ',' 1976-01-01 00:00:01 '), (9,' b ' '', '', 'A', '1977-01-01 00: 00:01'), (10, 'b', '', 'abcity2', '', '1978-01- 01 00:00:01 '); I want to ask what I have to give: 'a', 'xyz', 'abcity2', 'a' 'b', ' Sdf ',' abcity2 ',' b '
I do not want to use a query where I get empty values for each column of the table and then joining it as Include 100 columns in my actual table, this is a very complex task.
I have discovered a solution for the past and we have not got anything.
Thanks
It can be "tricky" for watching
There should be a twin-table ( a primary key to tester2
) to create the new table pub_name
to get the first data collected And all the columns you want to add, then include a key in the duplicate update
. This query will basically rebuild the tester
But without some of the duplicates and data collected so:
tester2 (pub_name, pubutt, country, no_of_branch) Insert pub_name Tester ordered by Strad update duplicate key, pubutt, country Choose no_of_branch pub_city = coalesce (Tester2.pubutt, tester.pubutt), country = millennium (tester2.country, tester.country), no_of_branch = coalesce (tester2.no_of_branch, tester.no_of_branch)
< p> PUB_NAME PUB_CITY COUNTRY NO_OF_BRANCH an xyz abcity2 AB SDF abcity2 a
take a look.
Note: I assume that you value the actual NULL
and do not have empty string like the sample given by you.
Comments
Post a Comment