Interview Questions, java interview questions

Source: Internet
Author: User
Interview questions, java interview questions
1. Use case when to perform subqueries

 SELECT u.id user_id, u.username user_username, g.id group_id,
  CASE g.flag
  WHEN '0' THEN g.groupcode
  ELSE (SELECT t.fullname FROM tab_0009 t WHERE t.id = g.id)
  END AS group_groupname,
 CASE g.flag
  WHEN '0' THEN g.groupname
  ELSE (SELECT t.fullcode FROM tab_0009 t WHERE t.id = g.id)
  END AS group_groupcode,
u_g.id usergroup_id, u_g.user_id usergroup_userId, u_g.group_id usergroup_groupId
FROM user_group u_g RIGHT JOIN t_group g ON u_g.group_id = g.id LEFT JOIN t_user u ON u_g.user_id = u.id
2. Externally connect t_group and tab_0009, and finally stitch the fields
SELECT u.id user_id, u.username user_username, g.id group_id,
CONCAT (IFNULL (g.groupname, ''), IFNULL (t.fullname, '')) group_groupname,
CONCAT (IFNULL (g.groupcode, ''), IFNULL (t.fullcode, '')) group_groupcode,
u_g.id usergroup_id, u_g.user_id usergroup_userId, u_g.group_id usergroup_groupId
FROM user_group u_g, t_user u, t_group g LEFT JOIN tab_0009 t ON t.id = g.id WHERE u_g.group_id = g.id AND u_g.user_id = u.id;

SELECT u.id user_id, u.username user_username, g.id group_id,
CONCAT (IFNULL (g1.groupname, ''), IFNULL (t.fullname, '')) group_groupname,
CONCAT (IFNULL (g1.groupcode, ''), IFNULL (t.fullcode, '')) group_groupcode,
u_g.id usergroup_id, u_g.user_id usergroup_userId, u_g.group_id usergroup_groupId

FROM user_group u_g RIGHT JOIN t_group g ON u_g.group_id = g.id LEFT JOIN t_user u ON u_g.user_id = u.id,
t_group g1 LEFT JOIN tab_0009 t ON t.id = g1.id WHERE g1.id = g.id;

SELECT u.id user_id, u.username user_username, g.id group_id,
g.groupname group_groupname,
g.groupcode group_groupcode,
u_g.id usergroup_id, u_g.user_id usergroup_userId, u_g.group_id usergroup_groupId
FROM user_group u_g RIGHT JOIN t_group g ON u_g.group_id = g.id LEFT JOIN t_user u ON u_g.user_id = u.id
 WHERE g.flag! = 0
 
UNION
 SELECT u.id user_id, u.username user_username, g.id group_id,
(SELECT t.fullname FROM tab_0009 t WHERE t.id = g.id) group_groupname,
(SELECT t.fullcode FROM tab_0009 t WHERE t.id = g.id) group_groupcode,
u_g.id usergroup_id, u_g.user_id usergroup_userId, u_g.group_id usergroup_groupId
FROM user_group u_g RIGHT JOIN t_group g ON u_g.group_id = g.id LEFT JOIN t_user u ON u_g.user_id = u.id
 WHERE g.flag = 0
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.