向Mysql表1的A,B,C三列插入数据,D列根据C列数据生成降序排序,用存储过程怎么写?

向Mysql表1的A,B,C三列插入数据,D列根据C列数据生成降序排序,用存储过程怎么写?,第1张

select agentid,sum(good) as good,sum(normal) as normal,sum(bad) as bad

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

结果:


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7165595.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-02
下一篇2023-04-02

发表评论

登录后才能评论

评论列表(0条)

    保存