Home > database >  Help bosses SQL code
Help bosses SQL code

Time:09-22

Everyone has a SQL problem bosses, want to ask, such as customer table contains cust_Id, cust_info two columns, respectively, the data is 123, the food; 123, null; 124, null; 125, null;
I am going to put inside cust_info are null cust_id select out the result is 124125, not 123, because 123 has a cust_info have value,

I think of is empty cust_id left join value cust_id,
Want to ask is there more simplified way, thanks for the great god ~ ~

CodePudding user response:

Don't know what you need to format, wrote two, you see which is you need to,


The SELECT tc ust_id FROM (
The SELECT tc ust_id, MAX (tc ust_info) m the FROM (
SELECT '123' cust_Id, 'food' cust_info FROM DUAL UNION ALL
SELECT '123', NULL FROM DUAL UNION ALL
SELECT '124', NULL FROM DUAL UNION ALL
SELECT '125', NULL FROM DUAL) t GROUP BY tc ust_id) t WHERE t.m IS NULL.



The SELECT GROUP_CONCAT (tc ust_id) FROM (
The SELECT tc ust_id, MAX (tc ust_info) m the FROM (
SELECT '123' cust_Id, 'food' cust_info FROM DUAL UNION ALL
SELECT '123', NULL FROM DUAL UNION ALL
SELECT '124', NULL FROM DUAL UNION ALL
SELECT '125', NULL FROM DUAL) t GROUP BY tc ust_id) t WHERE t.m IS NULL.

CodePudding user response:

Select * from table where cust_info is null
  • Related