I am trying to retrive the most popular field value for an attribute and then in a separate SQL query find the second most popular field attribute and then the third etc. I need each query to be separate to dynamically generate a series graph.
You could also use an Aggregate query, where you "Group By" the field in question, and also "Count" the same field. You might want to then ORDER BY that field in descending order, in order to present the data in "waterfall" format; eg.
SELECT SomeField, COUNT(SomeField)
FROM SomeTable
GROUP BY SomeField
ORDER BY SomeField
To avoid using a crosstab query, you could go into the OLE Chart object (double click on it), and set the "Data", "Series in Columns" menu options.
Either way, certainly no reason to need to use multiple queries. This method also avoids requiring a crosstab.
(a) I presented my solution as an alternative; not necessarily better or worse.
(b) "Avoid"ing the crosstab does provide the benefit of returning a table with a predictable structure, including predictable field headings. Personally, I use crosstabs only where I NEED to; if the chart facility inherently provides the option to transform the data for me, then I dont need to use them (different story though with reporting of course).
(c) I'd reckon that the non crosstab version provides better performance (though you could counter argue that the charting transformation has to do more "work" then ... but with a lot less data)
(d) Sometimes crosstabs are necessary, sometimes they're not; this provides an example of where they're not. Why use something, if its not required.
(e) Having said all of this, the crosstab approach does provide the benefit of allowing better higher level control of the chart's X-Axis by virtue of its ability to specify a set of static column names in the PIVOT .. IN clause.
Armed with a number of options, the experience (gaining) user can make a more informed decision,
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.