thinkphp sql语句问题

thinkphp sql语句问题,第1张

$user=M('user')

$where['_string']

=

'

((check1=$id

and

state1=0)

OR

(check2=$id

and

state1=1

and

state2=0)

OR

(check3=$id

and

state1=1

and

state2=1

and

state3=0))'

$list=$user->join('apply

ON

user.id=apply.uid')->where($where)->select()

试看看,若两表没重复字段应该可以,不行再追问。

你的问题有N多问题,说说我的建议,

通常,假如一张表纪录包子米饭的销售纪录

ID 售出类型 售出数量 售出时间

id typenum time

1 baozi 102013.08.01 15:30

2 mifan 212013.08.01 11:30

查米饭今天的销售纪录 就

select sum(num) from table where type = 'mifan' and time >2013.08.01 00:00:00 and time <2013.08.01 23:59:59

当然这里的时间比较只是比较直观点的,具体比较时肯定用时间戳格式的,,,,

简单明了,

然后回到你的问题,

你已经查询出了1.1号的包子销量,你现在需要做的就是要查出1.1号的米饭数量对吧

TP我以前玩过,是MVC的,这样的话,你其实可以这样,

在取当天销售包子的数据时,根据日期查询当天的米饭数量,然后一同放进数组,然后的模板里直接打印,

直观点就是原本一个数组

<?php

$data=array('20130101'=>array('baozi'=>12),

'20130102'=>array('baozi'=>16))

foreach($data as $k=>$v){

select sum(mifan) from table where 时间在20130101这天,

得到数量$n

$data[$k]['mifan']=$n

}

这样下来数组$data就会变成:

$data=array('20130101'=>array('baozi'=>12,'mifan'=>...),

'20130102'=>array('baozi'=>16,'mifan'=>...))

你直接在模板文件里取对应字段值就可以了,

因为没看到你的代码,所以解释的可能不清,有问题欢迎追问,

追问

Select url, Count(*) As c From `".$begin."` where is_uid='1' and ref_type='sina' group by url ORDER BY `c` desc

$begin 是一个表,表是按照时间命名的

我用的是thinkphp 3.2.3, 如果你没用用thinkphp5.0以上的,你可以试一下M('INFORMATION_SCHEMA.TABLES')->where(array('TABLE_SCHEMA'=>'数据库名'))->field('TABLE_NAME')->select()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9927033.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存