Sqlite错误包括where子句可以帮助我的任何人

时间:2015-02-12 14:40:30

标签: mysql sql sqlite

SELECT contactPhoneID, contactName, contactNumber, contactNumberType,
  contactEmail, contactImage, contactSortKey, contactCountryCode,
  contactRingTone, contactStatus, contactTimeStamp, contactMoodName,
  contactMoodType, contactEmotiUserFlag, contactSpeedDialID,
  contactSpeedDialFlag, contactFavorites, GROUP_CONCAT(contactNumber) AS contactNumber,
  contactName
FROM CONTACT_TABLE
WHERE contactFavorites = 'TRUE'
GROUP BY contactPhoneID

你好得到错误where where子句在它旁边添加它完美地工作

1 个答案:

答案 0 :(得分:0)

为了使您的查询正常工作,您需要按所有非聚合列进行分组:

SELECT contactPhoneID, contactName, contactNumber, contactNumberType,
  contactEmail, contactImage, contactSortKey, contactCountryCode,
  contactRingTone, contactStatus, contactTimeStamp, contactMoodName,
  contactMoodType, contactEmotiUserFlag, contactSpeedDialID,
  contactSpeedDialFlag, contactFavorites, GROUP_CONCAT(contactNumber) AS contactNumber,
  contactName
FROM CONTACT_TABLE
WHERE contactFavorites = 'TRUE'
GROUP BY contactPhoneID, contactName, contactNumber, contactNumberType,
  contactEmail, contactImage, contactSortKey, contactCountryCode,
  contactRingTone, contactStatus, contactTimeStamp, contactMoodName,
  contactMoodType, contactEmotiUserFlag, contactSpeedDialID,
  contactSpeedDialFlag, contactFavorites

MySQL支持非标准分组行为,如果按少于所有非聚合列进行分组,则每个唯一组将返回一个随机行。 AFAIK,如果你尝试这个,所有其他数据库都会抛出语法异常。