你能帮帮我吗? [英] Can you please help me for this
问题描述
你好朋友,
我在下面的查询中遇到困难,请尽量做到......
以下是我的表:
Hello Friends,
I got stuck in the following query, Kindly do the needful...
Following is my Table :
CREATE TABLE IF NOT EXISTS `exam_marks` (
`emid` int(11) NOT NULL AUTO_INCREMENT,
`eid` int(11) NOT NULL,
`sid` int(11) NOT NULL,
`mark` float NOT NULL,
PRIMARY KEY (`emid`)
)
和数据....
And Data....
INSERT INTO `exam_marks` (`emid`, `eid`, `sid`, `mark`) VALUES
(1, 3, 28, 15),
(2, 3, 29, 2),
(3, 3, 30, 15),
(4, 3, 31, 14),
(5, 3, 32, 15),
(6, 3, 33, 6),
(7, 3, 34, 15),
(8, 3, 35, 15),
(9, 3, 36, 15),
(10, 3, 37, 10),
(11, 3, 38, 11),
(12, 3, 39, 12),
(13, 3, 40, 13),
(14, 3, 41, 14),
(15, 3, 42, 15),
(16, 3, 43, 16),
(17, 3, 44, 17),
(18, 3, 45, 18),
(19, 3, 46, 19),
(20, 3, 47, 20),
(82, 7, 29, 10),
(84, 7, 31, 10),
(86, 7, 33, 15),
(90, 7, 37, 22),
(91, 7, 38, 33),
(92, 7, 39, 22),
(93, 7, 40, 22),
(94, 7, 41, 22);
Eid 3表示其常规考试和Eid 7表示其补救考试...我想准备以下报告:
****************************输出i想要的是如下*********
Sid reg rem
28 15 Null
29 2 10
30 15 Null
..
..
..
..
..
提前谢谢,
Eid 3 means its regular Exam and Eid 7 means its remedial exam... I want to prepare following report :
**************************** output i want is as follow*********
Sid reg rem
28 15 Null
29 2 10
30 15 Null
..
..
..
..
..
Thanks in advance,
推荐答案
这是一种情况,其中< a href =http://technet.microsoft.com/en-us/library/ms181765.aspx>案例 [ ^ ]会很有帮助。假设您有一张包含以下数据的表格:
This is one situation where CASE[^] would be helpful. Let's say you have a table with the following data:
User
ID Name Age
1 Bob 18
2 Chelsey 22
3 Rick 16
您想要一份报告来检查是否桌子上的条目是未成年人
and you want a report that checks if the entries on the table are minors
Name Minor
使用CASE,您可以编写以下查询:
Using CASE, you can write the following query:
SELECT Name,
CASE
WHEN Age < 18 THEN 'Yes'
ELSE 'No'
END As Minor
FROM User
输出将是
Output will be
Name Minor
Bob No
Chelsey No
Rick Yes
我写了以下查询...但它显示我只有两种记录:
I wrote following query... but it shows me only records exist in both :
select a.sid, a.mark as regmark, ifnull(b.mark,"") as remmark from exam_marks a, exam_marks b where a.sid = b.sid and a.eid=3 and b.eid=7
输出:
output :
sid regmark remmark
31 14 10
32 5 10
33 6 15
我想在列备注中包含空值。
I want to include null values for column remmarks also.
这篇关于你能帮帮我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!