shishuoxx 于 2014.03.14 17:37 提问

sql语句 多条件查询求解答

2个回答

lorewolf311   2014.03.14 18:18

select 试卷，max(成绩)，学生名字 from 学生 group by 试卷

qingzhishuishou   2014.03.14 18:21

CREATE TABLE [dbo].scores NOT NULL,
[name] varchar NULL,
[score] [int] NULL,
[paper] varchar NULL,
CONSTRAINT [PK_scores] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
sql：
SELECT (SELECT TOP 1 id FROM scores scc WHERE scc.paper=scores.paper ORDER BY scc.score DESC) AS bianhao,
(SELECT TOP 1 name FROM scores scc WHERE scc.paper=scores.paper ORDER BY scc.score DESC) AS NAME,
(SELECT MAX(score) FROM scores scc WHERE scc.paper=scores.paper) AS score,dbo.scores.paper
FROM dbo.scores GROUP BY paper

shishuoxx 非常感谢您！
4 年多之前 回复

SQL多条件查询Sql语句
DECLARE @startIndex INT, --用来判断的变量 @ordertype NVARCHAR(500), --条件语句 @SqlBase NVARCHAR(500) --最终的sql语句 SELECT @startIndex=3 SELECT @ordertype=CASE --根据条件组合sql语句 WHEN @startIndex=1 THEN 'OR
sqlserver多条件查询select语句合并

private void btnSelect_Click(object sender, EventArgs e) { //多条件查询 //只有在界面拼接sql语句了,使用两个List 来分别存储sql拼接语句和sql参数 List sqlList = new List(); List
MySQL多条件查询语句

sql拼接实现自由多条件查询及内容分页总结

C# SQL多条件查询拼接技巧

<br />  StringBuffer sqlBuf = new StringBuffer("select * from goods where");<br />  String sql="";<br />  if(!"".equals(g_name)){<br />   sqlBuf.append(" g_name='"+g_name+"'  and  ");<br />  }<br />  if(!"".equals(g_type)){<br />   sqlBuf.append(" g_type='