Question: I have a string with the following content

```
http://www.mysite.com/test.php?http://www.anotherwebsite.com

```

how can i save the second url in a php variable?

i mean, the url after the interrogation mark.

Answer: 
The type of query result you want is better done via client-side display-time manipulations. You can trivially get your data with:

```
SELECT year, SUM(sales)
FROM sales
WHERE product_id = 1
GROUP BY year

```
Although I totally agree with @MarcB, if you still want to do it your way you should run this query:

```
select product_id,
  sum(if(year = 2007, sales, 0)) `sales in 2007`,
  sum(if(year = 2008, sales, 0)) `sales in 2008`
from products
where product_id = 1
group by product_id

```

Note `sales in 2008` are not `3000` as you showed in your example but rather `4000`!