Home > database >  Help mysql masters, how to query the relational record?
Help mysql masters, how to query the relational record?

Time:09-23

Mysql database defined in a table, there are five columns were id, n_index, n_1 and n_2, n_3, as shown in the picture,


Given a query condition is that the user names,
Such as user is given a value "zhang", first according to the corresponding column n_x n_index find x, then watch n_x value is "zhang", if it is "zhang" remove this row data, graph of qualified "zhang SAN" record id have [2, 7, 10],
If the user has a given value is "detective", in line with the conditions of "detective" record id [1],
If the user has a given value is "liu qi," qualified "liu qi" on the record id have [3, 4, 6, 8].

CodePudding user response:

Law of fifty and really only one, is what ah,

CodePudding user response:

Cathy is only one id is 1

CodePudding user response:

Id is the line 9, there is also a detective,

CodePudding user response:

 
Select * from table where (case n_index when 1 then n_1 when 2 then n_2 when 3 then n_3 end)='liu seven'
# # or
Select * from table where the if (n_1 n_index=1, the if (n_index=2, n_2, n_3))='liu seven'
  • Related