Question: I have a table in a database with two three columns `ID, NAME, SUBJECT, SCORE`
There are only three possible values for subject `math, physics,biology` and for each there is a corresponding score in the score field. Because each student can take more than one course, the `NAME` column is not unique.

I want to expand the table such that each of the values for subject become a column so i no longer have the subject and score column, In other words I will have `NAME, MATH,PHYSICS,BIOLOGY` where the values of math physics and biology are the scores and the `NAME` column then becomes unique

I presently do this by using the query

```
SELECT T1.NAME, T2.SCORE AS BIOLOGY, T3.SCORE AS PHYSICS, T4.SCORE AS MATH
FROM studenttable T1
LEFT JOIN studenttable T2
ON T1.ID = T2.ID AND T2.SUBJECT = 'biology'
LEFT JOIN studenttable T3
ON T1.ID = T3.ID AND T3.SUBJECT = 'physics'
LEFT JOIN studenttable T4
ON T1.ID = T4.ID AND T4.SUBJECT = 'math'

```

This seems to work but I was wondering if there is a better way to achieve this? or a more tidier way ? Please do tell

Answer: 
Given your `writeHeader` is properly implemented this is almost correct. You need to fix 2 issues though:

1. You are writing one `int` per color channel. This should be one byte instead. You need to cast the literals to `unsigned char`.
2. Scanlines in bitmaps need to be `DWORD`-aligned. After your inner loop over `col` you need to write additional bytes to account for this, unless the size in bytes of the row is a multiple of four.
You need to force the output to be written in **binary** format, not text, this is chosen when you open your file/create your stream and to output all the values as bytes, not integers, this can be done in a number of ways possibly the easiest being write `chr(0)` or `chr(255)` - you also need to start your file with a header section - there are a number of formats that make this too long to go into in an answer here - some of them are down to preference as much as anything. There is a good summary in [Wikipedia](http://en.wikipedia.org/wiki/Bitmap_file_format#Bitmap_file_header).

Basically you have to inform the receiving applications which format you are using, the number of rows, columns and how the colours are stored.