Mysql Query question
I'm trying to work out the following query:
SELECT did_numbers.did_dialstring,
netareas.netarea_name,
did_numbers.did_size,
CASE WHEN (reseller_id < 1) IS NULL THEN 'F'
ELSE 'T'
END as reseller,
COUNT(*) AS aantal
FROM did_numbers
LEFT JOIN reseller_numbers ON (did_numbers.did_number = reseller_numbers.did_number AND reseller_numbers.did_number NOT IN(
SELECT did_number
FROM reseller_numbers
WHERE did_number
REGEXP '^31([0-9]{2,3})71([0-9]{4,5})$'
))
LEFT JOIN netareas ON did_numbers.did_dialstring = netareas.netarea_code
WHERE did_numbers.did_number NOT IN (
SELECT did_number
FROM did_numbers
WHERE did_number
REGEXP '^31([0-9]{2,3})71([0-9]{4,5})$'
)
GROUP BY did_numbers.did_dialstring, did_numbers.did_size, reseller
ORDER BY did_numbers.did_dialstring, reseller 开发者_开发知识库ASC
However, it does not seem to work. What happens is the numbers that are found in the subquery's are still counted. What am i doing wrong?
Thanks guys.
Here's my re-write of your query:
SELECT a.did_dialstring,
na.netarea_name,
a.did_size,
CASE
WHEN reseller_id IS NULL THEN 'F'
ELSE 'T'
END as reseller,
COUNT(*) AS aantal
FROM DID_NUMBERS a
LEFT JOIN RESELLER_NUMBERS rn ON rn.did_number = a.did_number
AND rn.did_number NOT REGEXP '^31([0-9]{2,3})71([0-9]{4,5})$'
LEFT JOIN NETAREAS na ON na.netarea_code = a.did_dialstring
LEFT JOIN DID_NUMBERS dn ON dn.did_number = a.did_number
AND dn.did_number NOT REGEXP '^31([0-9]{2,3})71([0-9]{4,5})$'
WHERE dn.did_number IS NULL
GROUP BY a.did_dialstring, a.did_size, reseller
ORDER BY a.did_dialstring, reseller ASC
If that's still returning the numbers you don't want to see, you're going to have to review the regex you're using to filter the numbers out.
精彩评论