douyue8364 2011-09-06 14:11
浏览 48
已采纳

嵌入式SQL请求

I have a SQL Database. In here is a table called Reports and it looks like this

ID       Date            Year     Title            Links
1        2010-05-03      2010     Report 1         link1.php
2        2010-09-03      2010     Report 2         link2.php
3        2011-01-05      2011     Report 3         link3.php

What I'm trying to achieve it the this. I want to select all the reports of 2010-2011 but the ones from 2010 may only be those dating from september.

Right now, I've got a SQL statement selecting all the reports of the two years

$sql = "SELECT * FROM Reports WHERE Year = ".$db->escape($jaar1)." OR jaar = ".$db->escape($jaar2);

How can I select Report 2 (cause it dates from september 2010) and Report 3 (cause it dates from 2011)?

  • 写回答

3条回答 默认 最新

  • doudeng5218 2011-09-06 14:15
    关注

    The easiest way as I see it, is to use the BETWEEN...AND operator.

    SELECT * 
    FROM `Reports`
    WHERE `Date` BETWEEN '2010-09-01' AND NOW()
    

    Note the backticks. Especially important around Date, because it is a reserved word.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#游戏策划#的问题:当浏览器输入兑换码,疯狂点击领取按钮,邮箱马上到账几十个兑换码礼包
  • ¥15 虚拟机打不开,怎么解决
  • ¥15 为什么游戏兑换码能被重复领取
  • ¥30 (急!)java实现二叉链表构建二叉树,实现相关功能
  • ¥15 C#tekloa节点插件小项
  • ¥20 脑电信号的局部场电位分析
  • ¥30 Diodes 霍尔开关AH337已经obselete,他的升级替代料【不改变现有电路图】
  • ¥15 python爬虫IndexError: list index out of range
  • ¥15 (标签-考研|关键词-set)
  • ¥15 求修改代码,图书管理系统