sql - C# get only top 10 highest selling items in database and put it to chart -
hi have code select products sales database , put chart, selecting products. how can 10?
and should query if need opposite top 10 least selling products?
code:
private void loadchart() { chart1.series[0].points.clear(); chart1.chartareas["chartarea1"].axisx.interval = 1; using (sqlconnection connection = new sqlconnection("data source=benjopc\\sqlexpress;initial catalog=marischelldatabase;integrated security=true")) { sqlcommand command = new sqlcommand("select productname, sum(qtysold) qtysold sales_productholder group productname", connection); connection.open(); sqldatareader read = command.executereader(); while (read.read()) { this.chart1.series["pieces sold"].points.addxy(read["productname"], read["qtysold"]); } read.close(); } }
try this:
select top 10 productname, sum(qtysold) qtysold sales_productholder group productname order sum(qtysold) desc sqlcommand command = new sqlcommand("select top 10 productname, sum(qtysold) qtysold sales_productholder group productname order sum(qtysold)", connection);
Comments
Post a Comment