Home > database >  One-to-many SQL queries
One-to-many SQL queries

Time:01-27

A table id name
B table id name A table id type



How to deal with this format


CodePudding user response:

Tell me something about the specific requirements,

CodePudding user response:

The subquery:
 
Select, Anderson d (select Max (name) from B to B where b.a ID=Anderson d and b.t ype=1) BName1, (select Max (name) from B to B where b.a ID=Anderson d and b.t ype=2) BName2, a.N ame from aa

CodePudding user response:

You can't get the maximum value in Chinese

CodePudding user response:

reference qq_33536878 reply: 3/f
you can't get the maximum value in Chinese

Can take, in addition to the name for aggregation, ensure compliance with B.A ID=Anderson D AND B.T YPE=2 this condition can only find out a name, lest out more qualified name, cause an error,

CodePudding user response:

The SELECT Anderson d AS [id] A table
, (CASE WHEN b.t ype=1 THEN b.n ame ELSE 'END) AS table name (type=1) [B]
THEN, (CASE WHEN b.t ype=2 b.n ame ELSE 'END) AS table name (type=2) [B]
, a.n ame AS [A table name]
FROM A table A
The JOIN table B B ON b.A table id=Anderson, d
  • Related