mysql忘却的一些语句

mysql忘却的一些语句

作者:LAMP小白  点击:1762  发布日期:2012-09-20 00:09:00  返回列表

今天暴露了一些不足,强化了一个晚上,写在这里以后再来看看,其实这种SQL根本不会实际应用在项目中,你在PHP端可以轻易的把这些句子转化成很简单的语句...那为什么要写呢?好吧,因为今天小小的受挫了

1.JS弹出新窗口是 window.open 今天居然犯了个这种2错误 想不起来了...

2.下面的这些东西写错了 一个,就是那个该死的 查出本日 本月的纪录 平时都在PHP里面取得时间戳 然后为表的时间戳字段建个索引 然后 num>$a num<$b 但今天被问到用一条SQL写,不准用PHP 然后打死都想不起字段转日期和日期转时间戳了 悲催...
排除重复的数据行
Select distinct name from user
查一个字段的重复值
select name,count(*) as num from user group by name having count(*) > 1
查出一个表的结果 然后写入另一个表
insert into haha (name,num) select A.name,A.num from (select name,count(*) as num from user group by name having num > 1) as A
查出一个公司的名称,并通过id关联的cid统计出另一张表的职位个数
select A.name,B.num from (select id,name from comname) as A,(select cid,count(*) as num from job group by cid) as B where A.id=B.cid
将数据库的一个字段存的时间戳 转换为 日期
select A.name,A.num,A.times from (select name,num,from_unixtime(num) as times from haha) as A
根据时间戳查出这一天的纪录
select A.name,A.num,A.times from (select name,num,date_format(from_unixtime(num),'%y-%m-%d') as times from haha) as A where A.times=date_format(now(),'%y-%m-%d'



上一篇:CentOS 5.5 PHP5.3.14 mysql Nginx攻略 下一篇:快递查询API
0