What would be the most efficient SQLish way of compiling a list of unique values, with record counts for each unique value, for all of the columns in a table?
对于表中的所有列,最有效的SQLish方法是编译唯一值列表,每个唯一值的记录计数是什么?
How would one differentiate columns with repeated values (such as country or state codes) versus columns that contain names and addresses - in which case there would be too many variations?
如何区分具有重复值的列(例如国家或州代码)与包含名称和地址的列 - 在这种情况下会有太多变化?
1 个解决方案
#1
1
For any single column, you can do:
对于任何单个列,您可以执行以下操作:
SELECT column, COUNT(*) AS column_count
FROM tablename
GROUP BY column
ORDER BY column
There isn't a simple way to do this for all columns in a single statement; you end up with the most awful multiple outer join with ordering problems and all sorts of issues to resolve. (Each separate column can have a different number of distinct values, for example.)
对于单个语句中的所有列,没有一种简单的方法可以执行此操作;你最终得到了最糟糕的多外连接,包括订购问题和需要解决的各种问题。 (例如,每个单独的列可以具有不同数量的不同值。)
The second half of your question ('how would one differentiate') is inscrutable; you have to know your data set to make that differentiation.
问题的后半部分(“如何区分”)是不可理解的;您必须知道您的数据集才能实现差异化。
#1
1
For any single column, you can do:
对于任何单个列,您可以执行以下操作:
SELECT column, COUNT(*) AS column_count
FROM tablename
GROUP BY column
ORDER BY column
There isn't a simple way to do this for all columns in a single statement; you end up with the most awful multiple outer join with ordering problems and all sorts of issues to resolve. (Each separate column can have a different number of distinct values, for example.)
对于单个语句中的所有列,没有一种简单的方法可以执行此操作;你最终得到了最糟糕的多外连接,包括订购问题和需要解决的各种问题。 (例如,每个单独的列可以具有不同数量的不同值。)
The second half of your question ('how would one differentiate') is inscrutable; you have to know your data set to make that differentiation.
问题的后半部分(“如何区分”)是不可理解的;您必须知道您的数据集才能实现差异化。