我正在设计一个使用 MSSQL Server 2005 的数据库来存储来自不同设备的日志值。值的数据类型可以是 boolean、int-32 或 64 bit-double
将有一个名为 的查找表channels:
ID(PK) | int32
device_name | varchar(32)
Run Code Online (Sandbox Code Playgroud)
将有一个表被调用values来存储该值。因此 boolean 和 int-32、double 值将被转换为 DECIMAL 数据类型。
ID(foreign key to ID@channels) | int32
logtime | DATETIME
value | DECIMAL
Run Code Online (Sandbox Code Playgroud)
我这样做的原因是最终用户可以在一个表上使用简单的 select 语句来选择数据,例如
select logtime,value from values where ID = 1不知道通道的数据类型。
但这是浪费内存,因为现在我将 int32 和 boolean 存储为 Decimal。我是数据库编程的新手,我想知道是否有人知道更好的方法来做到这一点?
问题的第一部分:
据我所知,Oracle DB中的RedoLog用于保护数据库免受数据丢失.据我所知,RedoLog的一个例子就是在事务中断后恢复数据.例如,如果意外关闭电力.但我无法理解数据库应用程序更改重做日志DB下次唤醒后直接?数据库提交是否在redoLog中直接更改为DataFiles.或者它只是启动事务并更改缓冲区中的块并将它们标记为脏?但是谁将这些脏块提交给DB文件呢?我怎么能继续被中断的交易?
问题的第二部分:
如果我有这个DML in transacion:让我们假设a = 1为id = 1
UPDATE test_table
SET a = (SELECT a FROM test_table WHERE id = 1) + 1
WHERE id = 1;
Run Code Online (Sandbox Code Playgroud)
我只是在TEST_TABLE中增加了A. 因此,如果事务失败,并且我的DML语句被写入RedoLog,则下次打开DB时将恢复它.但是,如果值的A变化与数据文件中的另一个数据库实例有关.RedoLog中的重做更改向量是什么(实际上可能会发生,可能是在ORACLE RCA中?)它会增加旧值还是新值?
我为我糟糕的英语道歉.将欣赏任何答案.
我有一个项目本质上是一个游戏服务器,用户通过telnet连接和发送文本命令.
代码是在C中,非常古老和非模块,并有几个错误和缺少功能.仅主要功能是代码的一半.
我得出的结论是,使用Twisted在Python中重写它实际上可以带来更快的完成,除了其他好处.
所以,问题是:我应该使用哪些软件包和模块?我在"protocols"包中看到了一个"telnet"模块.我还看到"cronch"包带有"ssh"和另一个"telnet"模块.
我是Python的完全新手.
我试图将值插入表的选定列,但只插入MySQL语句的结果.select语句本身可以正常工作并返回结果.
当与insert语句结合使用时,它将失败
error incorrect syntax near `dedspgoods`.`case number`.
Run Code Online (Sandbox Code Playgroud)
任何人都可以用正确的语法帮助我吗?我的错误语法如下:
insert into despgoods_alldetails
(`case number`, weight, customer, transporttypename)
values
( select despgoods.`case number`
, despgoods.weight
, despgoods.customer
, customers.transporttypename
from despgoods
inner join customers
on despgoods.customer = customers.customer )
Run Code Online (Sandbox Code Playgroud) 我有一个表,其数据如下所示:
INSERT INTO `cm_case_notes` (`id`, `case_id`, `date`, `time`, `description`, `username`, `supervisor`, `datestamp`) VALUES
(45977, '1175', '2010-11-19 16:27:15', 600, 'Motion hearing...Denied.', 'bjones', 'jharvey,', '2010-11-19 21:27:15'),
(46860, '1175', '2010-12-11 16:11:19', 300, 'Semester Break Report', 'bjones', 'jharvey,', '2010-12-11 21:11:19'),
(48034, '1175', '2011-05-04 17:30:03', 300, 'test', 'bjones', 'jharvey,', '2011-05-04 22:30:03'),
(14201, '1175', '2009-02-06 00:00:00', 3600, 'In court to talk to prosecutor, re: the file', 'csmith', 'sandrews', '2009-02-07 14:33:34'),
(14484, '1175', '2009-02-13 00:00:00', 6300, 'Read transcript, note taking', 'csmith', 'sandrews', '2009-02-16 17:22:36');
Run Code Online (Sandbox Code Playgroud)
我正在尝试为date每个用户选择每个案例的最新案例说明(by …
我有两个表 - 一个叫customer_records,另一个叫customer_actions.
customer_records 具有以下架构:
CustomerID (auto increment, primary key)
CustomerName
...etc...
Run Code Online (Sandbox Code Playgroud)
customer_actions 具有以下架构:
ActionID (auto increment, primary key)
CustomerID (relates to customer_records)
ActionType
ActionTime (UNIX time stamp that the entry was made)
Note (TEXT type)
Run Code Online (Sandbox Code Playgroud)
每次用户对客户记录执行操作时,都会输入一个条目customer_actions,并且用户有机会输入一个注释.ActionType可以是少数几个值之一(如'设计更新'或'添加案例信息' - 只能是选项列表中的一个).
我希望能够做的是显示customer_records最后ActionType一个特定值的记录列表.
到目前为止,我已经搜索了网/ SO并想出了这个怪物:
SELECT * FROM (
SELECT * FROM (
SELECT * FROM `customer_actions` ORDER BY `EntryID` DESC
) list1 GROUP BY `CustomerID`
) list2 WHERE `ActionType`='whatever' LIMIT …Run Code Online (Sandbox Code Playgroud) 我正在编写一个mysql查询并收到错误.
"'字段列表'中的未知列'dat'"
由于在mysql的IF条件中使用别名而发生此错误.
这是mysql查询:
SELECT
nCustomerID,
dDateRegistered,
(select count(nPlayerID) from credit_logs
where nPlayerID=nCustomerID) as total_clog,
(select count(nPlayerID) FROM bl_transaction_history
where nPlayerID=nCustomerID) as total_tran,
(select count(nCustomerID) from customer_freeplays
where nCustomerID=nCustomerID) as total_free,
(select dDateAdded from bl_transaction_history
where nPlayerID=nCustomerID) as dat,
(select DATEDIFF(now(),dat)/30 ) as date_differece1,
(select DATEDIFF(now(),dDateRegistered)/30 ) as date_difference2,
IF (dat IS NOT NULL,(select DATEDIFF(now(),dat)/30 ),
(select DATEDIFF(now(),dDateRegistered)/30 )) as date_difference
FROM bl_customers
WHERE nAccountStatus=1
and bDeleted=0
having total_clog>0
or total_tran>0
or total_free>0
Run Code Online (Sandbox Code Playgroud)
任何帮助都会被appriciated .. :)
提前致谢.
我有以下SQL Server表
我想要从下表中最新的所有前4个不同的代码
记住我希望返回所有列而不仅仅是代码列.
sno city state country code date
1 new york NY US 1234 1/1/2013
2 Houston TX US 2234 1/6/2013
3 LA CA US 1123 1/2/2013
4 Chicago IL US 1244 1/3/2013
5 Brooklyn NY US 1234 1/4/2013
6 Dallas TX US 2234 1/5/2013
Run Code Online (Sandbox Code Playgroud)
我的以下选择查询返回重复的代码,但我想要不同的最新代码.
select top 4 * from table1 where code in (select distinct code from table1)
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
我试图通过向慢查询日志中出现的查询添加索引来提高锤击wordpress DB的性能.
在MS SQL中,您可以使用查询提示强制查询使用索引,但如果正确覆盖列,则通常很容易获得查询以使用索引.
我有这个查询出现在慢查询日志中很多
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish')
ORDER BY wp_posts.post_date DESC
LIMIT 18310, 5;
Run Code Online (Sandbox Code Playgroud)
我在on wp_posts上创建了一个覆盖唯一索引post_date, post_status, post_type and post_id并重新启动MySQL但是当我运行解释时使用的索引是
status_password_id
Run Code Online (Sandbox Code Playgroud)
并且在可能的键中我的新索引甚至没有出现,尽管它是覆盖索引,例如我得到的
type_status_date,status_password_id
Run Code Online (Sandbox Code Playgroud)
因此,如果MySQL有一个"优化器",那么使用的索引或可能的选择都不会考虑我的post_date作为第一列的索引.我本来以为一个查询基本上是做一个TOP并按日期排序
ORDER BY wp_posts.post_date DESC LIMIT 18310, 5;
Run Code Online (Sandbox Code Playgroud)
是否希望使用按日期排序的索引来获取速度,尤其是具有满足查询所需的所有其他字段的索引?
MySQL是否有查询提示强制索引用于速度/性能测试,或者我还需要做些什么来查看为什么忽略这个索引.
如果Navicat有一个像MS SQL这样的可视化查询执行计划,我会很喜欢它,但似乎EXPLAIN是它提供的最好的.
任何有关如何强制使用索引或解决为什么被忽略的提示的人都会非常有帮助!
谢谢
我一直在寻找一段时间,似乎无法在任何地方找到它.我想知道如何选择列中的100个最高值和100个最低值?MIN功能仅选择最低的一个,MAX选择最高的一个.
谁在那里谁知道你这样做?