我有一个mysql数据库表,其结构是:
startphoneNum | endphoneNum | department
022589893232011 | 022589893232021 | sales
022589893232027 | 022589893232029 | Human Resources
022589893232041 | 022589893232048 | after sales
电话号码由3部分组成:022(城市代码) - 589893232(公司号码) - 011(分机号码)
我可以使用php explode,从022-589893232-011
到022589893232011
格式创建一个电话号码,然后如何通过phone number
放置mysql query
来获取{{1} }}?
例如:
如果我拨打电话号码department name
,则该号码属于022589893232043
,
但是如何在代码中创建after sales
?得到我需要的结果?谢谢。
答案 0 :(得分:8)
使用BETWEEN这样的查询:
SELECT department FROM table WHERE '022589893232043' BETWEEN startphoneNum AND endphoneNum;
答案 1 :(得分:1)
尝试此查询:
SELECT department
FROM table1
WHERE startphoneNum >= PHP_VARIABLE AND endphoneNum <= PHP_VARIABLE
答案 2 :(得分:1)
查看BETWEEN
运算符:
$query = "SELECT department
FROM myTable
WHERE '$phoneNbr' BETWEEN startphoneNum AND endphoneNum;";
答案 3 :(得分:1)
试试这个:
SELECT department FROM your_table
WHERE LEFT(your_num, 12) = LEFT(startphoneNum, 12)
AND CONVERT(RIGHT(your_num, 3), UNSIGNED) BETWEEN
CONVERT(RIGHT(startphoneNum, 3), UNSIGNED) AND
CONVERT(RIGHT(endphoneNum, 3), UNSIGNED)
答案 4 :(得分:0)
select department from [table] where [phone number] > startphonenum AND [phonenumber] < endphonenum
用实际值替换[] ...
答案 5 :(得分:0)
从部门dp,phonenumber_table pn中选择dp.department_name,其中pn.startphonenum&gt; 'values'和pn.endphonenum&lt; “值