varsha dodiya

varsha dodiya

  • NA
  • 407
  • 75.2k

sql group by order by problem in C#

Jul 23 2014 2:42 AM
i have table STOCK look like dis

S_en  S_P_name  S_supName  S_qty_avail   S_Pur_rate   S_batchno  S_Expdate 
1            crocin           aaa            5                    10            b8             jul-14
2           disprin           bbb             8                     8            d8              may-20
3           crocin           Opening        2                     0            aj9            apr=20
4         combiflame       kkk              4                     2             s9             may-15
5           disprin             kkk           3                       5            k9             aug-21


here u can see disprin has two Supplier one is bbb and other is kkk ...

I want my resultant table should be shown like this in datagridview

S_no   S_P_name  S_supName     S_qty_avail       S_Pur_rate
1          crocin            aaa             (5+2=)7                   10
2          disprin           kkk             (8+3=) 11                   5

3         combiflame      kkk                    4                         2



hi friends ,
here u see above , medicine name should not be repeated and
see case of Crocin == this product has Sup_name 'aaa' and 'Opening' too
the line selected in pink color in table,  this should not be shown in result table

means P_name having Opening as their Sup_name should not be shown .. clear .
-
the column marked with blue color is only to explain u the order of showing Sup_name (i.e. acc to their min Pur_rate)
we dont want it to be shown in result .

now u can see the resultant table is sorted alphabetically in S_sup_name ... and those names are shown which are providing product with min pur_rate

thanks for reading.
help me in this plz

Answers (19)