0

I am trying to simplify my problem. I have a mysql table like this:

meta_key       meta_value
rdv_0_date   12082013
rdv_1_date   13082013
rdv_0_time   12h
rdv_1_time 
rdv_place    Paris

I want as my query result two row:

1. 12082013 12h
2. 13082013 

SELECT * from mytable AS mt1
LEFT JOIN mytable AS mt2
WHERE mt1.meta_key LIKE 'rdv_%s_date'
OR mt1.meta_key LIKE rdv_%s_time'
4

1 回答 1

0

Are you looking for something like this?

SELECT mt1.meta_value, mt2.meta_value
FROM mytable AS mt1
LEFT JOIN mytable AS mt2 ON (SUBSTRING(mt1.meta_key, 5, 1) = SUBSTRING(mt2.meta_key, 5, 1))
WHERE mt1.meta_key LIKE 'rdv\__\_date'
AND mt2.meta_key LIKE 'rdv\__\_time';

I must agree with the previous comment, though, about the convenience of doing this with a not-really-efficient query like this one. If you're using a language on top of MySQL (like PHP) there could be better ways.

于 2013-05-20T13:47:33.487 回答