在一组MFRNO,MFRNAME,MFRADDRESS和ZIPCODE中 如果有两个电话号码,如果一个电话号码是空的(''),则从中删除,然后从结果中删除。 但如果在一个组中只有1条记录且电话号码为空白,那么它应保留在输出中。
DECLARE @TABLE TABLE
(
MFRNO VARCHAR(50),
MFRNAME VARCHAR(50),
MFRADDRESS VARCHAR(50),
ZIPCODE VARCHAR(50),
FIRSTPHONE VARCHAR(50)
)
INSERT @TABLE
SELECT '10008886', 'TIPMASTER LTD', 'RIGG APPROACH', 'E107ON','' UNION ALL
SELECT '10008886', 'TIPMASTER LTD', 'RIGG APPROACH', 'E107ON', '02085390611'UNION ALL
SELECT '10012227', 'CAR BODY', 'UNSHINAGH LANE', 'BT623RL', '' UNION ALL
SELECT '40045002', 'MANCHESTER', 'GROVE PARK', 'WA168QE', '' UNION ALL
SELECT '40045002', 'MANCHESTER', 'GROVE PARK', 'WA168QE', '07967967404'
MFRNO MFRNAME MFRADDRESS ZIPCODE FIRSTPHONE
10008886 TIPMASTER LTD RIGG APPROACH E107ON 02085390611
10012227 CAR BODY UNSHINAGH LANE BT623RL
40045002 MANCHESTER GROVE PARK WA168QE 07967967404
由于
答案 0 :(得分:1)
Max应该这样做:
select MFRNO, MFRNAME, MFRADDRESS, ZIPCODE, MAX(FIRSTPHONE)
from @TABLE
group by MFRNO, MFRNAME, MFRADDRESS, ZIPCODE