我有一个表allData
id name 1 meat 2 chicken 3 fish 4 chicken 5 fish 6 chicken
和table relatedData
id name 1 meat 2 fish
我想计算allData
中每个名称的总发生次数,但仅限于relevantData
中显示的名称。即
我想得到的结果:
id name count 1 meat 1 2 fish 2
我想到了查询:
Select count(*) from allData group by name
不确定我与relevantData
的关联方式。有什么想法吗?
答案 0 :(得分:2)
更改观点,您对relevantData
感兴趣,这是您查询的基础。您可以使用相关子查询,无需使用join或group-by:
SELECT rd.name,
(SELECT COUNT(*) FROM allData ad WHERE rd.name = ad.name) AS Count
FROM relevantData rd
答案 1 :(得分:0)
您可以尝试以下操作。
SELECT COUNT(*) FROM allData WHERE name in (SELECT name from relevantData) GROUP BY name
答案 2 :(得分:0)
只需加入他们:
SELECT a.id, a.name, COUNT(*) AS CntCol
FROM allData a
INNER JOIN relevantData r ON a.name = r.name
GROUP BY a.id, a.name
答案 3 :(得分:0)
试试这个:
java -cp lucene-core-4.3.0.jar -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex /opt/solr/cores/necc_db/index.20141215164500013
ERROR: could not read any segments file in directory
org.apache.lucene.index.CorruptIndexException: codec mismatch: actual codec=Lucene41NormsMetadata vs expected codec=segments (resource: ChecksumIndexInput(MMapIndexInput(path="/opt/solr/cores/necc_db/index.20141215164500013/segments_vilq")))
at org.apache.lucene.codecs.CodecUtil.checkHeaderNoMagic(CodecUtil.java:140)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:290)
at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:347)
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:783)
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:630)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:343)
at org.apache.lucene.index.CheckIndex.checkIndex(CheckIndex.java:382)
at org.apache.lucene.index.CheckIndex.main(CheckIndex.java:1854)
只需按ID分组,然后检查它是否包含在relatedData
中