Retuner kun en linie til brug ved joints
Relaterer til http://www.eksperten.dk/spm/722173Mit problem består i at jeg har en select sætning der returnere flere linier, hvilket ikke gør den egnet til at joine
Prefix type
20 mobil
21 mobil TDC
30 mobil
3011 mobil Sonofon
40 mobil
409 ISDN
7894 Prefix til kendt operatør
WHERE '30' LIKE CONCAT(prefix,'%') ORDER BY LENGTH(prefix) DESC
retunere
3011 mobil Sonofon
30 mobil
Jeg vil kun have bedste match. til denne sætning, hvis der er nogen der kan komme med et bedre alternativ en joints, godtages det også som svar
SELECT id,qda_d.number, Time as Timestamp,MAKETIME(TimeHours,TimeMin,0)as time, Condcode,
DialedNum, qda_d.type ,qda_d.name,qda_d.description,
MAKETIME(DurHours,DurMin,(Dur10ofMin*0.6)*10) as Duration
FROM col_data_test c, qos_digit_all qda_d
WHERE DialedNum LIKE CONCAT(qda_d.number,'%')
order by id
table dif for col_data_test
CREATE TABLE `col_data_test` (
`id` int(10) unsigned NOT NULL auto_increment,
`Time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`TimeHours` varchar(2) collate latin1_danish_ci default NULL,
`TimeMin` varchar(2) collate latin1_danish_ci default NULL,
`DurHours` varchar(1) collate latin1_danish_ci default NULL,
`DurMin` varchar(2) collate latin1_danish_ci default NULL,
`Dur10ofMin` varchar(1) collate latin1_danish_ci default NULL,
`CondCode` varchar(1) collate latin1_danish_ci default NULL,
`DialedNum` varchar(15) collate latin1_danish_ci default NULL,
`CallingNum` varchar(10) collate latin1_danish_ci default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci PACK_KEYS=0 COMMENT='InnoDB free: 11264 kB';
qos_digit_all qda_d er et view
output kunne se således ud
type number name description
local 7432 Møde city
local 7433 PNL
local 7440 CJO
local 7444 IBB
global 01004 TDC Mobil Operatørforvalgskode
global 0201 TDC Mobil GSM/UMTS
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `qos_digit_view` AS select `q`.`prefix` AS `prefix`,`qp`.`Name` AS `provider`,`qt`.`Name` AS `service` from ((`qos_digit_list` `q` join `qos_digit_provider` `qp`) join `qos_digit_type` `qt`) where ((`q`.`provider` = `qp`.`id`) and (`q`.`type` = `qt`.`id`));