Spielzeug
Spielzeug

Reputation: 37

I don't know how to write a query to display some specific information

I am trying to display some information from a SQL database and I don't know exactly how to write the query. I have a table which contains the "name" and the "studentship" of some students. What I have to do is to display the name, the studentship's value and to add another column(alias "Place") which contains the text "first" for the ones who have the studentship equal to 300, "second" for another studentship values. How can I do this? Thank you in advance!

Upvotes: 1

Views: 125

Answers (2)

Roberto Gonçalves
Roberto Gonçalves

Reputation: 3434

Try this:

SELECT NAME, STUDENTSHIP, IF(STUDENTSHIP = 300, 'first', 'second') FROM TABLE

Related question:

How to create virtual column using MySQL SELECT?

Upvotes: 1

JNevill
JNevill

Reputation: 50034

You'll use a CASE statement for your place field:

 SELECT name, 
     studentship, 
     CASE WHEN studentship=300 THEN 'first' WHEN studentship = <another one?> THEN 'second' END as place
 FROM yourtable;

Upvotes: 1

Related Questions