sql 经典一
1.建表
create table temp(rq varchar(10),shengfu nchar(1))
2.插入数据
insert into temp values('2005-05-09','胜')
insert into temp values('2005-05-09','胜')
insert into temp values('2005-05-09','负')
insert into temp values('2005-05-09','负')
insert into temp values('2005-05-10','胜')
insert into temp values('2005-05-10','负')
insert into temp values('2005-05-10','负')
3.sql
select rq as '日期',sum(case when shengfu ='胜' then 1 else 0 end) as '胜' ,sum(case when shengfu='负' then 1 else 0 end) as '负' from temp group by rq
4.测试一下吧。。
日期 胜 负
2005-05-09 2 2
2005-05-10 1 2
相关文档:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DAL
{
......
in 的话, 如果是null 就不比较了,既不是in 也不是 not in
exists的话 因为用 = 加在条件里比较了,所以 null 是 not exists
select *
from pricetemp
where cast(商品コード as varchar(10))not in(
select shohin_cd
&nbs ......
1.首先需要建立plan table,否则不能使用
建立方法:
$oracle\rdbms\admin下有个
utlxplan.sql
其内容为:
create table PLAN_TABLE (
statement_id varchar2(30),
timestamp date,
remarks varchar2(80),
operat ......
1 :普通SQL语句可以用exec执行
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname fr ......