我正在对此产生问题,我希望这样做是可能的。
我的表格是一字塔,储存了元数据,因此无法改变栏目和实地数据(容易)。
因此,表结构是
post_id meta_key meta_value
the meta key stores a field name and the meta_value, the value for that field. I need to group these based on the post ID so I can then do a compare between two of the fields. I ve tried all sorts!!
因此,数据如下:
post_id meta_key meta_value
1 _wp_field0 10
1 _wp_field1 5
1 _wp_field2 9
1 _wp_field3 "matt s post"
1 _wp_field3 155
2 _wp_field0 51
2 _wp_field1 9
2 _wp_field2 18
2 _wp_field3 "james post"
2 _wp_field3 199
I ve do a group_CONCAT which Return
post_id concat
1 10,5,9,matt s post,155
2 51,9,18,James post,199
这是我最接近的一步,来了解我想要的东西。 但是,我不敢肯定的是,如何把这一点分开。 我有一整套我想比较的内容(领域1和2)。
我需要上述数字的第二和第三。 我能做些什么来解决这些问题? 然后,我想做一些数学。 它们是基本浮标,储存着长度和纬度,我想加以比较和距离。
I was thinking of having a temp table? All I need is to reference those two numbers. Maybe I can split the string up by separator??
我已经摆脱了想法。
DROP FUNCTION get_lat;
DELIMITER $$
CREATE FUNCTION get_lat(in_post_id INT)
RETURNS FLOAT
READS SQL DATA
BEGIN
DECLARE latitude FLOAT;
SELECT meta_value INTO latitude FROM wp_postmeta WHERE post_id = in_post_id AND meta_key = field1 ;
RETURN (latitude);
END $$
DELIMITER;
DROP FUNCTION get_lon;
DELIMITER $$
CREATE FUNCTION get_lon(in_post_id INT)
RETURNS FLOAT
READS SQL DATA
BEGIN
DECLARE longitude FLOAT;
SELECT meta_value INTO longitude FROM wp_postmeta WHERE post_id = in_post_id AND meta_key = field2 ;
RETURN (longitude);
END $$
DELIMITER;
SELECT post_id,get_lat(post_id)as latitude, get_lon(post_id) as longitude FROM wp_postmeta GROUP BY post_id;