tags:

views:

30

answers:

2

dear all..i have this data inside DB:

line     model        serial      
fa01     kd-g335ud   105x0001     
fa01     kd-g335ud   105x0002     
fa01     kd-g335ud   105x0003 //up to 20pcs or regardless of the number of goods in the db
fa02     kd-r311ed   105x0001
fa02     kd-r311ed   105x0002 //up to 20pcs or regardless of the number of goods in the db

i want if every "model" have reached 20 pcs or regardless of the number of goods in the db, the data will appear at quantity page like:

line     model      qty
fa01    kd-g335ud    20
fa02    kd-r311ed    20

please help, thanks before :-)

+2  A: 

SELECT line, model, count(serial) as qty FROM table_name GROUP BY line, model

Not 100% sure on my query, but that is along the lines of what you want. Hopefully that query is correct!

Brad F Jacobs
after the result appear, how to ditribute the result to the quantity page?
klox
Through using the php mysql functions? For a tutorial on how to do this: http://www.siteground.com/tutorials/php-mysql/display_table_data.htm (not sure on the quality of that tutorial).
Brad F Jacobs
+2  A: 

you are not explaining it well. you said "i want if every "model" have reached 20 pcs or regardless of the number of goods..." what about the line. regardless of the line or in regards :)? If you want every model regardless of the line and serial then:

SELECT model, count(model) AS QUANITY FROM [table name] GROUP BY model;
Neo