有没有办法在SQL查询中查看哪些字符替换%/ wildcard?
说
$exhibitions = $wpdb->get_results( "SELECT * FROM wp_postmeta
WHERE meta_key LIKE 'dates_%_startdate'
ORDER BY meta_value
LIMIT 0 , 30" );
如果结果中的meta_key-column是'dates_0_startdate',我想以某种方式得到零。
答案 0 :(得分:2)
SELECT *, replace(replace(meta_key, 'dates_', ''), '_startdate', '')
FROM wp_postmeta
WHERE meta_key LIKE 'dates_%_startdate'
ORDER BY meta_value
LIMIT 0 , 30
答案 1 :(得分:1)
只是警告,在MSSQL中,下划线是单字符通配符。
http://technet.microsoft.com/en-us/library/ms179859.aspx
同样在MySQL中显然是:http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
答案 2 :(得分:1)
SELECT REPLACE(REPLACE(meta_key,'dates_',''),'_startdate','')
FROM wp_postmeta
WHERE meta_key LIKE 'dates_%_startdate'
ORDER BY meta_value
LIMIT 0 , 30
答案 3 :(得分:0)
取决于您使用的SQL形式。如果你正在使用MSSQL(你不是你的get_results的东西),你可以使用SUBSTRING返回像SUBSTRING(表达式,开始,长度)一样的信息
get_results( "SELECT SUBSTRING(meta_key, 7, 1) FROM wp_postmeta
WHERE meta_key LIKE 'dates_%_startdate'
ORDER BY meta_value
LIMIT 0 , 30" );