久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

TSQL For Filter Experice From Range multiselect

TSQL For Filter Experice From Range multiselect(TSQL For Filter Experice From Range multiselect)
本文介紹了TSQL For Filter Experice From Range multiselect的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的表包含經驗字段,它是一個整數.并且我的頁面包含一個復選框列表,如 0-3,3-7,7-9,9-12,12-15,15+ 年,我必須使用選擇查詢從表中過濾它我試過 between but it is not working when multiple fields selected can any one help

My Table contain Experience Field which is an integer . and my page contains a check box list like 0-3,3-7,7-9,9-12,12-15,15+ years and i have to filter this from table using select query i have tried between but it is not working when multiple fields selected can any one help

我的表結構就像

Name    Experience in year
----    ---------
a          1
b          2
c          3
d          5
e          2
f          1

我的數據庫參數是一個 varchar 字符串

My parameter for database is a varchar string

if we select 0-3years then  '0-3' 
if we select 3-6years then  '3-6' 
if we select both  then  '0-3,3-6' 
if we select 0-3years and 9-12years then '0-3,9-12'

現在我以這些格式發送數據我不知道這是一個好方法請告訴我更好的方法

Now i am sending Data in these format i dont know it is a good method please show me the better way

推薦答案

首先你需要一個表 checkRanges

First you need a table checkRanges

CREATE TABLE checkRanges
    ([checkID] int, [name] varchar(8), [low] int, [upper] int);

INSERT INTO checkRanges
    ([checkID], [name], [low], [upper])
VALUES
    (1, '0-3', 0, 2),
    (2, '3-6', 3, 5),
    (4, '6-9', 6, 8),
    (8, '9-12', 9, 11),
    (16, '12+', 12, 999)

看到 checkID 是 2 的冪嗎?

See how checkID are power of 2?

在您的應用中,如果用戶選擇 3-69-12,您將 2+8 = 10 發送到您的數據庫.如果您使用數據庫信息創建復選框也會很棒.

In your app if user select 3-6 and 9-12 you send 2+8 = 10 to your db. Also would be great if you create your check box using the db info.

在您的數據庫中,您進行按位比較以選擇正確的范圍.然后對每個范圍執行 between.

In your db you do bitwise comparasion to select the right ranges. Then perfom the between with each range.

WITH ranges as (
    SELECT *
    FROM checkRanges
    where checkID & 10 > 0
)
SELECT *
FROM users u
inner join ranges r
   on u.Experience between r.low and r.upper

一起查看SQL Fiddle 演示我包括更多的用戶.您只需要更改條款 where checkID &10 >0 測試其他組合.

See it all together SQL Fiddle Demo I include more users. You only have to change the clausule where checkID & 10 > 0 to test other combination.

注意:
我更新了范圍.將上限值更改為 value - 1,因為 between 是包含性的,可能會產生重復的結果.

NOTE:
I update the ranges. Change the upper value to value - 1 because between is inclusive and could give duplicate results.

如果要使用舊版本,您必須將連接語句中的betwewen替換為

If want use old version you have to replace the betwewen in the join sentence to

u.Experience >= r.low and u.Experience *<* r.upper

這篇關于TSQL For Filter Experice From Range multiselect的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 欧美99 | 国产精品一区二区在线 | 男人天堂色| 欧美日韩在线视频一区二区 | 精品国产91 | 99热在这里只有精品 | 婷婷桃色网 | 国产精品96久久久久久 | 精品一区二区三区免费视频 | 国产伦精品一区二区三区高清 | 国产一区2区 | 国产激情91久久精品导航 | 久久综合久久综合久久综合 | 九九热最新地址 | 亚洲h色 | 欧州一区二区三区 | 成人午夜激情 | 久久久不卡网国产精品一区 | 日韩一级免费电影 | 中文字幕高清av | 亚洲精品久久久久久国产精华液 | 黑人性hd| 91在线精品秘密一区二区 | 欧美日韩中文字幕在线 | 国产精品美女久久久免费 | 91爱爱·com| 国产成人av在线播放 | 天堂资源 | 在线观看亚洲精品 | 国产免费一区二区三区 | 国产在线精品一区 | 欧美成人a∨高清免费观看 老司机午夜性大片 | 欧美日韩精品免费观看 | 亚洲日本中文 | 国产欧美精品区一区二区三区 | 国产精品久久久久久中文字 | 中文字幕av一区二区三区 | 久久成人一区 | 日本久久久久久 | 日一日操一操 | 一级毛片在线视频 |