现在的情况是:我知道数据库table,知道一个字段值是name,name又很多记录,全是以G开头的,有G1-G7,G10XXXX-G89XXXX,G9XXXX。我现在要做一个查询:将G1-G7的查询出来,怎么写sql语句?就是 select * from table where ......? 然后G10XXXX-G89XXXX中第三位,也就是第二个数字是奇数的查询出来怎么做?是偶数的查询出来怎么做? 还有就是G9XXXX的一组查询出来怎么做? 请分别写出四个sql语句中where的内容,谢谢
第一个:select * from table where name like 'G[1-7]%' 第二个:select * from table where (convert(int,substring(name,3,1)) % 2)=0 第三个:select * from table where (convert(int,substring(name,3,1)) % 2)=1 第四个:select * from table where name like 'G9%'
如果是要查询整个表的所有类容,方法如下: select * from tableName; 如果是要查询特定条件下的表的类容,方法如下: select * from tableName where 条件; 如果是要查询表里的制定字段的值,方法如下: select colName from tableName; 如果要查询制定字段,特定条件下的值,方法如下: select colName from tableName 条件;