How to write a SQL query to find the range from column values? The 2019 Stack Overflow...
Make it rain characters
Do I have Disadvantage attacking with an off-hand weapon?
Do warforged have souls?
Simulating Exploding Dice
How do you keep chess fun when your opponent constantly beats you?
Mortgage adviser recommends a longer term than necessary combined with overpayments
One-dimensional Japanese puzzle
What is the padding with red substance inside of steak packaging?
Was credit for the black hole image misappropriated?
How did the crowd guess the pentatonic scale in Bobby McFerrin's presentation?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
Word to describe a time interval
Deal with toxic manager when you can't quit
What information about me do stores get via my credit card?
Word for: a synonym with a positive connotation?
Is an up-to-date browser secure on an out-of-date OS?
Am I ethically obligated to go into work on an off day if the reason is sudden?
Why can't devices on different VLANs, but on the same subnet, communicate?
Single author papers against my advisor's will?
What force causes entropy to increase?
What do I do when my TA workload is more than expected?
Is this wall load bearing? Blueprints and photos attached
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
How to write a SQL query to find the range from column values?
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)From a set of values, how do I find the values not stored in a table's column?MySQL-How to find that value in a column is subset with all other values in same column multiple timeSelect Multiple Values from Same Column; one sql statement and split into separate columnsOptimized MySQL “optional” FULLTEXT search on multiple tablesSelect data but allow users and groups to supersede everyone dataMySQL: Find Extra Days From List Of Date RangesMySQL: Loop on each column value & split column by delimiter & replace numbers with values from another columnHow to query a table with different values on the same fields?Replace Null values with values from the same column by matching values in a different columnHow to get same column values to make multiple columns?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have some fields in my database which contain values like 2483-5802 and 1245-3325.
Now I have a user input and I have to find it from this column.
Example if I have to search 2000 which will come in range 1245-3325.
So how I can write a query to find that 2000 belongs to 1245-3325 this range?
mysql
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have some fields in my database which contain values like 2483-5802 and 1245-3325.
Now I have a user input and I have to find it from this column.
Example if I have to search 2000 which will come in range 1245-3325.
So how I can write a query to find that 2000 belongs to 1245-3325 this range?
mysql
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Which RDBMS are you using?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:56
thats mysql database.
– Joomler
Apr 20 '16 at 6:56
How come the value 2000 belongs to the 2483-5802 range? Shouldn't it belong in the 1245-3325 range?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:58
that was just an example. but thanks ill update my question :)
– Joomler
Apr 20 '16 at 6:59
3
The start and end of the range should be stored in 2 separate integer columns. Not in one varchar column.
– ypercubeᵀᴹ
Apr 20 '16 at 7:08
add a comment |
I have some fields in my database which contain values like 2483-5802 and 1245-3325.
Now I have a user input and I have to find it from this column.
Example if I have to search 2000 which will come in range 1245-3325.
So how I can write a query to find that 2000 belongs to 1245-3325 this range?
mysql
I have some fields in my database which contain values like 2483-5802 and 1245-3325.
Now I have a user input and I have to find it from this column.
Example if I have to search 2000 which will come in range 1245-3325.
So how I can write a query to find that 2000 belongs to 1245-3325 this range?
mysql
mysql
edited Apr 20 '16 at 7:00
Joomler
asked Apr 20 '16 at 6:44
JoomlerJoomler
1268
1268
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Which RDBMS are you using?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:56
thats mysql database.
– Joomler
Apr 20 '16 at 6:56
How come the value 2000 belongs to the 2483-5802 range? Shouldn't it belong in the 1245-3325 range?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:58
that was just an example. but thanks ill update my question :)
– Joomler
Apr 20 '16 at 6:59
3
The start and end of the range should be stored in 2 separate integer columns. Not in one varchar column.
– ypercubeᵀᴹ
Apr 20 '16 at 7:08
add a comment |
Which RDBMS are you using?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:56
thats mysql database.
– Joomler
Apr 20 '16 at 6:56
How come the value 2000 belongs to the 2483-5802 range? Shouldn't it belong in the 1245-3325 range?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:58
that was just an example. but thanks ill update my question :)
– Joomler
Apr 20 '16 at 6:59
3
The start and end of the range should be stored in 2 separate integer columns. Not in one varchar column.
– ypercubeᵀᴹ
Apr 20 '16 at 7:08
Which RDBMS are you using?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:56
Which RDBMS are you using?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:56
thats mysql database.
– Joomler
Apr 20 '16 at 6:56
thats mysql database.
– Joomler
Apr 20 '16 at 6:56
How come the value 2000 belongs to the 2483-5802 range? Shouldn't it belong in the 1245-3325 range?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:58
How come the value 2000 belongs to the 2483-5802 range? Shouldn't it belong in the 1245-3325 range?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:58
that was just an example. but thanks ill update my question :)
– Joomler
Apr 20 '16 at 6:59
that was just an example. but thanks ill update my question :)
– Joomler
Apr 20 '16 at 6:59
3
3
The start and end of the range should be stored in 2 separate integer columns. Not in one varchar column.
– ypercubeᵀᴹ
Apr 20 '16 at 7:08
The start and end of the range should be stored in 2 separate integer columns. Not in one varchar column.
– ypercubeᵀᴹ
Apr 20 '16 at 7:08
add a comment |
1 Answer
1
active
oldest
votes
As follows (replace yourtable
and each of the two instances of rangefield
):
SELECT *
FROM `yourtable`
WHERE ? BETWEEN CAST(`rangefield` AS int) AND CAST(MID(`rangefield`, LOCATE('-', `rangefield`)+1) AS int);
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f135874%2fhow-to-write-a-sql-query-to-find-the-range-from-column-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As follows (replace yourtable
and each of the two instances of rangefield
):
SELECT *
FROM `yourtable`
WHERE ? BETWEEN CAST(`rangefield` AS int) AND CAST(MID(`rangefield`, LOCATE('-', `rangefield`)+1) AS int);
add a comment |
As follows (replace yourtable
and each of the two instances of rangefield
):
SELECT *
FROM `yourtable`
WHERE ? BETWEEN CAST(`rangefield` AS int) AND CAST(MID(`rangefield`, LOCATE('-', `rangefield`)+1) AS int);
add a comment |
As follows (replace yourtable
and each of the two instances of rangefield
):
SELECT *
FROM `yourtable`
WHERE ? BETWEEN CAST(`rangefield` AS int) AND CAST(MID(`rangefield`, LOCATE('-', `rangefield`)+1) AS int);
As follows (replace yourtable
and each of the two instances of rangefield
):
SELECT *
FROM `yourtable`
WHERE ? BETWEEN CAST(`rangefield` AS int) AND CAST(MID(`rangefield`, LOCATE('-', `rangefield`)+1) AS int);
answered Apr 20 '16 at 7:04
Ziggy Crueltyfree ZeitgeisterZiggy Crueltyfree Zeitgeister
4,2951819
4,2951819
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f135874%2fhow-to-write-a-sql-query-to-find-the-range-from-column-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Which RDBMS are you using?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:56
thats mysql database.
– Joomler
Apr 20 '16 at 6:56
How come the value 2000 belongs to the 2483-5802 range? Shouldn't it belong in the 1245-3325 range?
– Ziggy Crueltyfree Zeitgeister
Apr 20 '16 at 6:58
that was just an example. but thanks ill update my question :)
– Joomler
Apr 20 '16 at 6:59
3
The start and end of the range should be stored in 2 separate integer columns. Not in one varchar column.
– ypercubeᵀᴹ
Apr 20 '16 at 7:08