开发者

how to counting from data array?

i have some data at DB like:

qty       item  id  date
0001-0500 abcd  1   2010-06-22
0001-0500 abcd  2   2010-06-22
0001-0500 abcd  3   2010-06-22

i want some script can make them order by date and show result :

qty : 500 (it means 500-1=500,number 1 read 1-1 = 0)
item : abcd
id : 3 (counting from 1 until 3)
date :2010-06-22

qty    item     id   date
500    abcd     3     2010-06-22

i have tried like this:

'SELECT qty, item, COUNT(*) FROM inspec GROUP BY date';

before use the c开发者_运维技巧ode above,i still confuse to make changes at :

qty       
0001-0500 
0001-0500      =>result become:qty : 500 (it means 500-1=500,number 1 read 1-1 = 0)
0001-0500


Sorting and counting can be (and I'd say usually are) done at the database level, using SQL. Otherwise, there are language constructs that can do the heavy lifting for you, again, called sort and count.

If you're using MySQL, the tutorial is a good place to start learning. For PHP, you might find this book helpful.


i have tried like this:

'SELECT item, COUNT(*) FROM inspec GROUP BY date';

If you want qty, shouldn't you SELECT it as well?

'SELECT item, COUNT(*), qty FROM inspec GROUP BY date';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜