Home > database >  Merge SQl query name sector determine according to time
Merge SQl query name sector determine according to time

Time:04-05

 SELECT 
'test' enter oneself for an examination the AS jobs,
Users. Departname AS department,
Tb_cjk tb_cjk_jh AS student id,
Users. The username AS name,
Tb_cjk tb_cjk_time AS the test time,

MAX (CASE WHEN tb_cjk_typename='mathematics' THEN tb_cjk. Tb_cjk_cj END) AS mathematics,
MAX (CASE WHEN tb_cjk_typename='language' THEN tb_cjk. Tb_cjk_cj END) AS Chinese,
MAX (CASE WHEN tb_cjk_typename='English' THEN tb_cjk. Tb_cjk_cj END) AS English
The FROM
Tb_cjk
LEFT OUTER JOIN the Users ON tb_cjk. Tb_cjk_jh=Users. The userid
WHERE
(1=1)
GROUP BY
Users. The username,
Tb_cjk tb_cjk_jh,
The Users departname,
Users. Birth,
Tb_cjk. Tb_cjk_time
The ORDER BY
CHARINDEX (Users. Departname 'departments'), student id

The above is the actual query, such as: the WHERE (0=0) can query to the time when the exam results, and do not show time, WHERE (=1) as can query to all the test time record but same day is separated from the different subjects, can help change, thank you! The final result, it is show (date) (month) (year) to merge two subjects,
  • Related