type TA struct { Id int64 `db:"id"` } type TB struct { Id int64 `db:"id"` } type TC struct { TA TB } 如上的sql和结构体, 当查询sql,用TC结构体封装时, 有两个id字段, 那么数据库中id的值是在TB的id中 如果TC的结构体是 type TC struct { TB TA } 这样, 那么id的值就是在TA中
SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT (case when a.colorder=1 then d.name else '' end) as 表名,--如果表名相同就返回空 a.colorder as 字段序号, a.name as 字段名, (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' e
用的sqlserver2008 r2. SELECT * FROM t_class WHERE id IN (SELECT id FROM (SELECT ROW_NUMBER() OVER (PARTITION BY id ORDER BY inserttime) AS rn, id FROM t_class) myclass WHERE rn >= 5) ORDER BY id; 看起来好复杂,不知道有没有简单方法.
() UNION () UNION (select i.create_time as time,i.investment_amount as amount,i.invest_state as state, b.bid_name as type from invest i INNER JOIN bid b on i.bid_id=b.bid_id ) UNION (select r.exact_repayment_time as time,r.should_repayment_amount as
可以在查询时给字段赋别名,但是需要注意以下:*的位置要在最前面,放在其他地方都会出错.这种写法同名覆盖的字段还在,然后在*的后面加上别名字段,已经可以满足所有需求了 SELECT *,r.id as rid,u.id as uid FROM remarks_tblogs as r left join user_tblogs as u on r.userId=u.id ORDER BY r.id desc P.S. 一段thinkphp数据库查询代码,注意各种别名的使用 $remarks = M
1.查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like'%你要查询的字段名%') and id in(select id from sysobjects where xtype='u') order by objname ; 2.查询包含某字段的所有存储过程 SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments