好吧,所以我有一个看起来像这样的查询:
SELECT
`orders`.*,
GROUP_CONCAT(
CONCAT(
`menu_items`.`name`,
' ($',
FORMAT(`menu_items`.`price`,2),
')'
) SEPARATOR '<br>'
) as `items`,
SUM(`menu_items`.`price`) as `additional`,
`children`.`first_name`,
`children`.`last_name`,
`organizations`.`base_price`
FROM
`orders`, `order_items`, `menu_items`, `children`, `organizations`
WHERE
`order_items`.`menu_item_id` = `menu_items`.`id` AND
`order_items`.`order_id` = `orders`.`id` AND
`orders`.`added_by` = {$user_id} AND
`orders`.`date` > '{$cutoff}' AND
`children`.`id` = `orders`.`child_id` AND
`organizations`.`id` = `children`.`organization_id`
GROUP BY
`orders`.`id`
Run Code Online (Sandbox Code Playgroud)
我知道这是一个怪物,有些人会在不使用显式连接之前死掉.但是,忽略这一点,我想做的只是使用if CONCAT里面大于0,否则只返回.但是,我没有成功试图扔进那里.我已经阅读了手册,但我尝试过的所有方法都不起作用,我很确定我在整个条件语句中都缺少一些东西.GROUP_CONCATmenu_items.pricemenu_items.nameIF
我怎样才能做到这一点?(c#)基本上,我希望能够排序,注释掉括号.但不是真的.我想我想要不按顺序关闭括号.这可能是不可能的.我显然可以在完全独立的if子句中实现它,但这会大大减轻我的代码.
PS:我试图在foreach循环中放置"// do something"代码,或者根据条件将一个不相关的(与foreach循环的)参数放在一个实例中.我希望这有助于澄清它.
伪代码(我正在尝试做什么,如果你可以不按顺序关闭括号):
我知道这不是有效代码附近,它是我所说的伪代码.
我还没看过第二篇文章,但是第一篇文章(Sean Bright),谢谢,但条件与条目数无关(无论我是否希望循环执行,目录中总会有文件存在)
将// dosomething代码提取到函数中将起作用.我不确定我是如何忽视这一点的.我想我想知道是否有更简单的方法,但你是对的.谢谢.
if (isTrue)
{
//START LOOP
string [] fileEntries = Directory.GetFiles(LogsDirectory, SystemLogFormat);
foreach(string fileName in fileEntries)
{
using (StreamReader r = new StreamReader(fileName))
{
/* The previous two blocks are not closed */
}
else
{
using (StreamReader r = new StreamReader(SingleFileName))
{
/* The previous block is not closed */
}
// do all sorts of things
if (isTrue)
{
/* Close the two unclosed blocks …Run Code Online (Sandbox Code Playgroud) bool stop = false;
int f1 = 1;
int f2 = 2;
int f3 = 0;
int sum = 2;
while (!stop)
{
f3 = f1 + f2;
sum += f3 % 2 == 0 ? f3 : 0; //THIS ONE
stop = f3 > 4000000 ? true : false;//AND THIS ONE.
f1 = f2;
f2 = f3;
}
Run Code Online (Sandbox Code Playgroud)
什么是条件运算符?这是我第一次见到这样的东西.
我正在为我的网站编写侧边栏,我正在尝试检查是否:
is_post()current_user_can('edit_post')我试图结合这两个条件,但我对PHP很可怕,我只是无法弄清楚这样做的语法.我认为它会像下面那样.能不能让我知道我做错了什么?我假设它很简单,但我缺乏经验导致问题,我找不到合适的示例/文档来帮助我.
<?php if is_single and if (current_user_can('edit_post')) { ?> <li><a href="#">Edit post</a></li> <?php ;} ?>
我在SQL服务器中有一个视图,它从一个模式版本转换为另一个模式版本.
目前,视图如下所示:
SELECT newValue AS oldValue
FROM dbo.MyTable
Run Code Online (Sandbox Code Playgroud)
麻烦的是,在新模式中,newValue不可为空,因此我们将其设置为-1表示空字段,但在旧模式中,它可以为空.
我该怎样做才能达到以下效果:
SELECT
(
IF( newValue > -1 )
newValue as oldValue
ELSE
NULL as oldValue
)
FROM dbo.MyTable
Run Code Online (Sandbox Code Playgroud) 伙计们,我有一个像这样的每小时温度数据
Lines <- "Date,Outdoor,Indoor
01/01 01:00:00,24.5,21.3
01/01 02:00:00,24.3,21.1
01/01 03:00:00,24.1,21.1
01/01 04:00:00,24.1,20.9
01/01 05:00:00,25.,21.
01/01 06:00:00,26.,21.
01/01 07:00:00,26.6,22.3
01/01 08:00:00,28.,24.
01/01 09:00:00,28.9,26.5
01/01 10:00:00,29.4,29
01/01 11:00:00,30.,32.
01/01 12:00:00,33.,35.
01/01 13:00:00,33.4,36
01/01 14:00:00,35.8,38
01/01 15:00:00,32.3,37
01/01 16:00:00,30.,34.
01/01 17:00:00,29.,33.
01/01 18:00:00,28.,32.
01/01 19:00:00,26.3,30
01/01 20:00:00,26.,28.
01/01 21:00:00,25.9,25
01/01 22:00:00,25.8,21.3
01/01 23:00:00,25.6,21.4
01/01 24:00:00,25.5,21.5
01/02 01:00:00,25.4,21.6
01/02 02:00:00,25.3,21.8"
Run Code Online (Sandbox Code Playgroud)
我需要创建另一个列,如果室内高于室外高度至少1度,则表示1.
我试过了:
DF$Time = 0
if ((Indoor-Outdoor) >= 1) DF$Time = 1
Run Code Online (Sandbox Code Playgroud)
但上述方法无效.有什么建议吗?
如果我有两个条件,每个条件都有一个动作,如果一个条件属实,则对两个条件都采取行动,
有时我这样做
if (cond1 or cond2)
if (cond1)
do act 1
if (cond2)
do act 2
do always
Run Code Online (Sandbox Code Playgroud)
有时我这样做
if (cond1)
do act 1
do always
if (cond2)
do act 2
do always
Run Code Online (Sandbox Code Playgroud)
但我真的很想这样做
if (cond1)
do act 1
or if (cond2)
do act 2
then
do always
Run Code Online (Sandbox Code Playgroud)
最后一种方法是否以任何语言存在,或者是否有一种处理这种情况的首选方法?
谢谢.
如何使这个正确?
if( $(this) == $(".className") ){
alert("Yes!");
}
Run Code Online (Sandbox Code Playgroud)
而且......
if( $(this) != $(".className") ){
alert("Yes!");
}
Run Code Online (Sandbox Code Playgroud)
谢谢
这个简单的条件赋值(是的,不幸的是我喜欢它!)不起作用.什么是范围$x和$i变量?
if($x = $s->getXAxis() && ($i = array_search($x, $this->xAxis)) !== false) // 88
$s->xAxis = $i; // 89
Run Code Online (Sandbox Code Playgroud)
我有:
注意:未定义的变量:第88行的x.
这可能是你在stackoverflow上找到的最容易回答的问题,但是我想一劳永逸地解决这个困惑.请考虑以下if语句:
if(x > 0)
{
echo 'Inside if';
}
// apparently there is a hidden else here....
echo 'This comes after if';
Run Code Online (Sandbox Code Playgroud)
现在考虑以下一个:
if(x > 0)
{
echo 'Inside if';
}
else
{
echo 'Inside else';
}
echo 'This comes after if/else';
Run Code Online (Sandbox Code Playgroud)
在第一个例子中,如果条件的计算结果为true,那么将打印"Inside if",但是if("This after after if")之后的内容也不会被打印出来吗?我的意思是,我没有返回我的if,所以代码应该继续正常,对吧?对于第二个if语句,同样的事情,在语句将被打印之后,因为代码的执行将继续正常.如果我们没有明确定义一个if语句,真的有一个虚拟的其他吗?我的意思是,如果在我的if语句之后出现的是条件是否评估为真,那么在我的if之后并没有真正的虚拟其他.另外,如果在if-then-else语句中绝对需要Else,而不是像第一个例子那样依赖"虚拟其他"?请详细说明一下.
谢谢
conditional ×10
if-statement ×3
php ×3
c# ×2
sql ×2
jquery ×1
logic ×1
loops ×1
mysql ×1
r ×1
sql-server ×1
t-sql ×1
views ×1
wordpress ×1