MySQL - How to SELECT based on value of another SELECT

前端 未结 3 1415
庸人自扰
庸人自扰 2021-01-30 06:22

I have a table that looks something like this:

Name    Year   Value
 A      2000     5
 A      2001     3
 A      2002     7
 A      2003     1
 B      2000              


        
3条回答
  •  感动是毒
    2021-01-30 07:13

    If you want to SELECT based on the value of another SELECT, then you probably want a "subselect":

    http://beginner-sql-tutorial.com/sql-subquery.htm

    For example, (from the link above):

    1. You want the first and last names from table "student_details" ...

    2. But you only want this information for those students in "science" class:

      SELECT id, first_name
      FROM student_details
      WHERE first_name IN (SELECT first_name
      FROM student_details
      WHERE subject= 'Science'); 
      

    Frankly, I'm not sure this is what you're looking for or not ... but I hope it helps ... at least a little...

    IMHO...

提交回复
热议问题