Home > Back-end >  [in] the MYSQL according to the query conditions to different query data in the table
[in] the MYSQL according to the query conditions to different query data in the table

Time:12-08

Have three tables, said t_ebook ebook table, t_videoinfo said video information table, t_study_type deposit type, 1 video class, 2 said e-books, now I need to do a query operation and, depending on the type of course grade, subjects these three conditions from the three tables in the query to information, such as I choose e-books, educations, the language, how to write at that time the Mysql statement? For bosses,
Ps: tried using an IF or a case and implementation, but both can only return a value or a string, unable to return multiple field values

CodePudding user response:

First write your hair up, including how you think,

CodePudding user response:

If my filter condition is e-books, educations, Chinese, so I'm going to select all educations, language classes of e-books and paging processing: SQL statements to write is a bit poor
SELECT
*,
IF
(
TST. Id=2,//2 ebook
(the SELECT t_ebook book_name FROM t_ebook where t_ebook. Id=1),
(the SELECT t_video_info video_name FROM t_video_info where t_video_info. Id=1)
) as the 'result'
The FROM
T_study_type as TST,
T_grade,
T_ebook,
T_video_info,
T_subject
Where
TST. Id=2
And
T_grade. Id=5//5 said in a
And
T_subject. Id=1//1 language

CodePudding user response:

If there is no, you can write two SQL, determine what type, if it is the ebooks will check selectEbook (returning to the List), check if the video is video selectVideo (returning to the List), don't choose type, it two methods are carried out and then put the two List in a resultList returns

CodePudding user response:

This also calculate a solution

CodePudding user response:

Why not now determine the type in the Java code to perform different conditions
  • Related