Interview Questions, java interview questions

Source: Internet
Author: User

Interview Questions, java interview questions

1. Use case when for subquery

 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_groupIdFROM 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. Connect t_group and tab_0009 as external connections, and splice the last field
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_groupIdFROM 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_groupIdFROM 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_groupIdFROM 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_groupIdFROM 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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.