
from
(select agentid,1 as good,0 as normal,0 as bad
from A where content=1
union all
select agentid,0 as good,1 as normal,0 as bad
from A where content=2
union all
select agentid,0 as good,0 as normal,1 as bad
from A where content=3
)B
group by agentid
delimiter$$
mysql>
mysql>
CREATE
PROCEDURE
myProc()
//创建while循环的存储过程
if分支语句示例
->
BEGIN
->
->
DECLARE
i
int
->
SET
i=1
->
loop1:
WHILE
i<=10
DO
->
IF
MOD(i,2)<>0
THEN
/*Even
number
-
try
again*/
->
SELECT
CONCAT(i,"
is
an
odd
number")
->
END
IF
->
SET
i=i+1
->
END
WHILE
loop1
->
END$$
Query
OK,
0
rows
affected
(0.00
sec)
这种也可以
MySQL中排序输出需要用order by。
如图,test表中有如下数据:
现在分别要求按ID正序和倒序输出结果。
正序:
select * from test order by id结果:
倒序:
select * from test order by id desc结果:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)