日期:2014-05-17  浏览次数:20439 次

简单的SQL语句那里出了问题
CREATE TABLE T_SCORE(DATE DATETIME NOT NULL,
NAME NVARCHAR(20),SCORE NVARCHAR(10) NOT NULL)
INSERT INTO T_SCORES(DATE,NAME,SCORE)VALUES('2008-8-9','拜仁','胜')
INSERT INTO T_SCORES(DATE,Name,SCORE)VALUES ('2008-8-9','奇才','胜')
INSERT INTO T_SCORES(DATE,NAME,SCORE)VALUES('2008-8-10','湖人','胜')
INSERT INTO T_SCORES(DATE,Name,SCORE)VALUES('2008-8-11','拜仁','负')
INSERT INTO T_SCORES(DATE,NAME,SCORE)VALUES ('2008-8-13','奇才','胜')
INSERT INTO T_SCORES(DATE,NAME,SCORE)VALUES ('2008-8-28','拜仁','负')

SELECT NAME as 球队,
(
CASE SCORE
WHEN '胜' THEN 1
ELSE 0
END ) AS 胜,
(
CASE SCORE
WHEN '负' THEN 1
ELSE 0
END
)AS 负
 FROM T_SCORE
怎么不显示数据

只显示 球队 胜 负

------解决方案--------------------
你这个写法就是只显示球队胜负啊
------解决方案--------------------
你看 你3个as
------解决方案--------------------
SELECT NAME as 球队,
(
CASE SCORE
WHEN '胜' THEN 1
ELSE 0
END ) AS 积分

FROM T_SCORE

------解决方案--------------------
查询sql没有问题 你的insert语句有问题 表名少了一个S
------解决方案--------------------
SELECT NAME as 球队,
sum(
CASE SCORE
WHEN '胜' THEN 1
ELSE 0
END ) AS 胜,
sum(
CASE SCORE
WHEN '负' THEN 1
ELSE 0
END
)AS 负
 FROM T_SCORE
 group by name
------解决方案--------------------
注意你插入数据的表和建立的表名称都不一样
------解决方案--------------------
SELECT 球队,sum(a.胜) 胜,sum(a.负) 负
FROM(
SELECT NAME as 球队,
(
CASE SCORE
WHEN '胜' THEN 1
ELSE 0
END ) AS 胜,
(
CASE SCORE
WHEN '负' THEN 1
ELSE 0
END
)AS 负
 FROM T_SCORE
) a GROUP BY a.球队
这是统计
------解决方案--------------------
你插入数据的表是T_SCORES,查的是T_SCORE表,不是一个表。

------解决方案--------------------
前后表名不一致