需要的想法:选择表中的行 [英] Need ideas: Selecting rows in table

查看:101
本文介绍了需要的想法:选择表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户开发一个网站.它需要一种特殊的方式来创建计算.在表中,我必须创建具有相同%End"的行组.

由于一开始(2011年11月24日)只有90%的一行,所以您只需忽略它. 例如,我必须选择带有日期的行

2011年11月26日 2011年11月28日 2011年11月29日

然后进行计算,稍后选择日期

2011年12月4日 2011年12月5日 2011年12月6日

日期为2011年12月7日和12月9日的行也将被忽略,因为在它们之前或之后都没有相同百分比的行.

以此类推.

我对如何做到这一点很迷茫.如何创建日期组以进行计算?有没有简便有效的方法?

我的资源"是PHP,jQuery和MySQL

感谢您的帮助,自星期一以来,我一直坚持这样做.

该表的信息是通过存储过程获取的 该表必须以90%的最终percert开始和结束

开始90%....任何值... 90%结束

edit3:这是我的存储过程(也许可以帮助更好地理解 http://pastebin.com/cZM1j72u )

要解决我的问题,我可以使用php,Javascript(jQuery)或mysql

这个想法是从2011年12月17日开始计算口袋妖怪的价值,从2012年12月14日开始减去.

该值将与12月14日的加仑"值相除. <--这就是我想要的.

解决方案

您需要哪种计算?我认为这是MySQL的基础.例如:

SELECT percent_end, SUM(cakes) as sumcakes
FROM table
GROUP BY percent_end

这只是每个%_END的蛋糕的SUM.使用GROUP BY.

如果您不需要%_END,而该记录只有一条记录:

SELECT percent_end, SUM(cakes) as sum_cakes, COUNT(date) as date_amount
FROM table
GROUP BY percent_end
HAVING date_amount > 1

I'm developing a site for a client. It requires a special way to create a calculation. In the table, i have to create groups of rows with the same "% End".

Since there are just one row with 90% at the begining (date November 24 2011) you just ignore it. For example, i have to select the rows with dates

November 26 2011 November 28 2011 November 29 2011

And then make the calculation, later select the dates

December 04 2011 December 05 2011 December 06 2011

Rows with date December 07 2011 and December 09 are ignored too because there's no rows with the same percent before or after them.

And so on.

I'm pretty lost on how to do it. How can i create groups of dates to calculate them? Is there an easy and efficent way to do it?

My "resources" are PHP, jQuery and MySQL

Any help is appreciated, i'm stuck with this since monday.

EDIT: the information for the table is fetched by a stored procedure EDIT2: the table must start and end with an final percert of 90%

Start 90%....any values...90% end

edit3: this is my stored procedure (maybe it can help to better understanding http://pastebin.com/cZM1j72u)

to solve my problem i can use php, Javascript( jQuery ) or mysql

the idea is take the pokemon's value from date December 17th 2011 and substract from December 14th 2012.

The value is going to be divided from Dec 14th 'Galons' value. <---That's what i'm looking for.

解决方案

What kind of calculation do you need? I think it's ground of MySQL. For example:

SELECT percent_end, SUM(cakes) as sumcakes
FROM table
GROUP BY percent_end

This is simply SUM of cakes by each %_END. use GROUP BY.

If you don't need %_END which has only one record:

SELECT percent_end, SUM(cakes) as sum_cakes, COUNT(date) as date_amount
FROM table
GROUP BY percent_end
HAVING date_amount > 1

这篇关于需要的想法:选择表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆