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语句了 水平不怎么样 写的有点复杂 这样行不?