sql條件選擇
A. sql多個條件篩選
1、創建測試表,create table test_con_x(company_name varchar(200), remark varchar2(200));
B. SQL如何有條件的限制選擇項
alter table s add constraint s_chk
check (a=1 and b in (0) or a=2 and b in (0,1) or a=3 and b in (0,1,2) or a=4 and b in (0,1,2,3))
C. sql語句按某一條件選擇查詢某表。
declare
varchartemp(10)
select@temp=zfromDB:Awhere...
if(@temp==1)
select*fromDB:Bwhere...
elseif(@temp==2)
select*fromDB:Cwhere...
elseif(@temp==3)
select*fromDB:Dwhere...
這個思路應該是這樣的,你自己把代碼補充完整,數據類型定好,希望能幫到你
D. SQL 條件只選擇一個
如果是 SQL Server 或 Access:
select top 1 ...
如果是 MySql:
select ... limit 1
E. SQL 多條件,任意選擇 查詢方法
實例 public java.util.List<Operator> selectOperatorsConditions(
HashMap<String, String> conditions, Connection conn) {
// 根據條件進行查詢操作員信息
java.util.List<Operator> operatorsByCondition = new ArrayList<Operator>(); StringBuffer sql = new StringBuffer(
"select operator_id,operator_name,is_admin from t_operator"); if (conditions.size() > 0) {
sql.append(" where ");
Iterator<String> keyset = conditions.keySet().iterator();
while (keyset.hasNext()) {
String cols = (String) keyset.next();
sql.append(cols + " = '" + conditions.get(cols) + "' and ");
}
sql.delete(sql.lastIndexOf("and"), sql.length());
}
Statement st = null;
ResultSet rs = null;
try {
if (conn != null) {
st = conn.createStatement();
rs = st.executeQuery(sql.toString()); while (rs.next()) {
Operator operator = new Operator(rs.getString(1), rs
.getString(2), rs.getString(3));
operatorsByCondition.add(operator);
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return operatorsByCondition;
}
F. sql 多條件篩選語句怎麼寫
1、創建測試表,create table test_con_x(company_name varchar(200), remark varchar2(200));
G. sql中的條件篩選!!!!
select id,sum(socre) as socre,type from A where type=17 group by id,type
union
select id,sum(socre) as socre,type from A where type<17 and type>12 and id not in (select id from A where type=17
) group by id,type
union
select id,sum(socre) as socre,type from A where type<13 and id not in (select id from A where type>12
) group by id,type
好久沒寫SQL語句了 水平不怎麼樣 寫的有點復雜 這樣行不?