I recently got into a situation where I wanted to know how many distinct values were in a column of a table. It would be nice to be able to use the following:
SELECT COUNT (DISTINCT column-name) FROM table-name
I recently got into a situation where I wanted to know how many distinct values were in a column of a table. It would be nice to be able to use the following:
SELECT COUNT (DISTINCT column-name) FROM table-name
If you just want to know how many distinct values there are in a column, you could do something like
query("SELECT column-name FROM table-name GROUP BY column-name"); int distinctValues = getquerymatchcount();
Of course that only works in some pretty specific cases but it may be enough to help you go forward for now.
Thanks @Mischa Spelt, I didn't understand exactly how GROUP BY works, but that should help a lot
How can I use DISTINCT to list out distinct values from the column into another table?
Already tried the following code and got the error "time: 0.000000 exception: FlexScript exception: Could not parse query SELECT DISTINCT ModelName FROM ProductionOrder at MODEL:/Tools/UserCommands/WriteStationMaps/code"
string sql4="SELECT DISTINCT ModelName \ FROM ProductionOrder"; Table result4=Table.query(sql4); result4.cloneTo(Table("UniqueModelNames"));
SELCT ModelName From ProductionOrder GROUP BY ModelName
In future please post a new question.
The DISTINCT keyword does have its uses, but many problems where you need it can be solved by using the Group by statement: This will give you a list where each new distinction of column name has its own row. Now you can iterate through the distinctions.
SELECT COUNT(*), [column-name] FROM table GROUP BY [column-name]
Share your great idea, or help out by voting for other people's ideas.
Adding the original row in the SQL query table to the dumpquery table by default/optional
Flexsim SQL Wishlist: NOT predicate, LEFT JOINs, DISTINCT, UNION, CRUD support
Adding foreign keys in Global Tables to maintain data integrity
Add the functionality of Left Join, Right Join and Full Outer Join capabilities to Table.query()
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved