Choose partial column name in MySQL

I am wondering if there is a way to select part of a column in mysql. For example, I want to select all statistics from my table that end in "_sep_2012". This will give me access to 1_sep_2012, 2_sep_2012, 3_sep_2012, etc. Is there any way to do this?

<?php
$query=mysql_query("SELECT %_sep_2012% FROM statistics WHERE id = '$id'");

$array = mysql_fetch_row($query);

$monthly_total = $array[0];

echo "$monthly_total";
?>

Any help would be greatly appreciated. Thank!

+5
source share
3 answers

According to your question, it should be possible to do something like:

SELECT * FROM statistics WHERE datecolumn LIKE '%_sep_2012'

Not to say this is good, but he should get the data you need. You can add GROUP BY offers to make an invoice or amount to get the total:

SELECT datecolumn, SUM(amountcolumn) FROM statistics WHERE datecolumn LIKE '%_sep_2012' GROUP BY datecolumn
+3
source

Write this in PHP:

for($i=1;$i<32;$i++)
  printf("`%d_sep_2012`, ", $i);
0
source

try it

SELECT * FROM statistics WHERE datecolumn LIKE '%_sep_2012' and id = '$id'
0
source

All Articles