Hi
I have a table with a column event_time. How can I select two rows right before NOW() and the next one after NOW(), ordered by event_time?
Is is possible with a single query?
I have a table, which looks like:
+-----------+----------+
+ person_id + group_id +
+-----------+----------+
+ 1 + 10 +
+ 1 + 20 +
+ 1 + 30 +
+ 2 + 10 +
+ 2 + 20 +
+ 3 + 10 +
+-----------+----------+
I need a query such that only person_ids with groups 10 AND 20 AND 30 are returned (only person_id: 1). I am not sure how to do this, as from what I can see it would require me to group the rows by person_id and then select the rows which contain all group_ids.
I'm looking for something which will preserve the use of keys without resorting to string operations on group_concat() or such.
This is a situation I'm generally facing while writing SQL queries. I think that writing the whole column (e.g. long case expressions, sum functions with long parameters) instead of aliases in GROUP BY expressions makes the query longer and less readable. Why doesn't Oracle SQL allow us to use the column aliases in GROUP BY clause? There must be an important reason behind it.
Does anyone know a good approach using Entity Framework for the problem described below?
I am trying for our next release to come up with a performant way to show the placed orders for the logged on customer.
Of course paging is always a good technique to use when a lot of data is available I would like to see an answer without any paging techniques.
Here's the story: a customer places an order which gets an orderstatus = PENDING. Depending on some strategy we move that order up the chain in order to get it APPROVED.
Every change of status is logged so we can see a trace for statusses and maybe even an extra line of comment per status which can provide some extra valuable information to whoever sees this order in an interface.
So an Order is linked to a Customer. One order can have multiple orderstatusses stored in OrderStatusHistory.
In my testscenario I am using a customer which has 100+ Orders each with about 5 records in the OrderStatusHistory-table.
I would for now like to see all orders in one page not using paging where for each Order I show the last relevant Status and the extra comment (if there is any for this last status; both fields coming from OrderStatusHistory; the record with the highest Id for the given OrderId).
There are multiple scenarios I have tried, but I would like to see any potential other solutions or comments on the things I have already tried.
Trying to do Include() when getting Orders but this still results in multiple queries launched on the database. Each order triggers an extra query to the database to get all orderstatusses in the history table. So all statusses are queried here instead of just returning the last relevant one, plus 100 extra queries are launched for 100 orders. You can imagine the problem when there are 100000+ orders in the database.
Having 2 computed columns on the database: LastStatus, LastStatusInformation and a regular Linq-Query which gets those columns which are available through the Entity-model.
The problem with this approach is the fact that those computed columns are determined using a scalar function which can not be changed without removing the formula from the computed column, etc...
In the end I am very familiar with SQL and Stored procedures, but since the rest of the data-layer uses Entity Framework I would like to stick to it as long as possible, even though I have my doubts about performance.
Using the SQL approach I would write something like this:
WITH cte (RN, OrderId, [Status], Information)
AS
(
SELECT ROW_NUMBER() OVER (PARTITION BY OrderId ORDER BY Id DESC), OrderId, [Status], Information
FROM OrderStatus
)
SELECT o.Id, cte.[Status], cte.Information AS StatusInformation, o.* FROM [Order] o
INNER JOIN cte ON o.Id = cte.OrderId AND cte.RN = 1
WHERE CustomerId = @CustomerId
ORDER BY 1 DESC;
which returns all orders for the customer with the statusinformation provided by the Common Table Expression.
Does anyone know a good approach using Entity Framework?
I've got a GET method that looks like the following:
GetMethod method = new GetMethod("http://host/path/?key=[\"item\",\"item\"]");
Such a path works just fine when typed directly into a browser, but the above line when run causes an IllegalArgumentException : Invalid URI.
I've looked at using the URIUtils class, but without success. Is there a way to automatically encode this (or to add a query string onto the URL without causing HttpClient to barf?).
Hi,
does anyone have any idea how I can get started building a search engine for my asp.net mvc site using entity framework. I plan to build something like: http://www.carsguide.com.au/search/?N=4294962119++492&type=cars
there on the left there is a refine search option panel.
What's the best approach to design a model for the UI and optimized query with entity framework.
Hi,
I am using Doctrine Update query as follow.
$oQuery = Doctrine_Query::create()
-update("Model")
-set("field",$value);
the problem is that if $value is string, I have to -set("field","'".$value."'");
if it normal? Why can't doctrine do it itself?
am I missing something?
Hi All,
I have a doubt. Assume R and S are 2 relations with attributes A and B respectively . If I have a query
Select *
From R, S
Where R.A = S.B
Does this work like a double For Loop in say c or c++
For( i=0; i<n; i++)
For( j=0; j<n; j++)
if (i == j)
//DO some work
When I add event handler to a some elements using query:
$('div').mouseover(function () {
});
how can I check inside this function next:
Have this "DIV"child elements
"DIV"?
Have this "DIV" child
element "DIV" whith height more than
300?
Can anyone help me write SQL script for the following formula?
If DEP = 1
If DROP 1
PLV = 334.86 * exp(0.3541 * ACTIVE_DAYS) + 0.25 * DROP + 20 * DEP
Else
If DROP < 0
PLV = DROP + 70 * ACTIVE_DAYS
Else
PLV = 0.25 * DROP + 70 * ACTIVE_DAYS
The SQL script which I have is the following
SELECT IF(dep=1, if(dep=1, (334.86 * exp(0.3541 * act_days)) +
(0.25 * 'drop') + (20 * dep),
if('drop'<0, 'drop' + (70 * act_days), (0.25 * 'drop') + (70 * act_days))),'0')
as PLV
But the above query is not right as something is missing where the formula says
Else
PLV = 0.26 * DROP
Thanks,
I have a email address like [email protected] and [email protected][email protected] ... etc
I want a Mysql select query so that it would trim user names and .com an returns output as
gmail,ymail,hotmail etc
hi
i need to search between date's and time's.
for example: between date: 30/02/2007 time: 10:32 and date: 21/06/2008 time: 14:19
what is the most simple query for this ?
thank's in advance
I am trying to query all post that are made to the wall of a facebook event. But am not making any headway. Is this at all possible. How would you proceed? Create a multiquery FQL statement?
Hi all, my question is simple but i cant fin de answer. Is there a way to set in Lucene to retrieve an amount of results higher than 100 in a query?
Im using lucene 2.4.0 now.
Thanks all.
I have to create an SQL Query to get all rows starting with a specific character, except if the parameter passed to the (PHP) function is 0, in that case it should get every row that does not start with A - Z (like #0-9.,$ etc).
What is the easiest and fastest way to get those rows?
DB: MySQL 5.1
Column: title
I have a doubt. Assume R and S are 2 relations with attributes A and B respectively . If I have a query
Select *
From R, S
Where R.A = S.B
Does this work like a double For Loop in say c or c++
For( i=0; i<n; i++)
For( j=0; j<n; j++)
if (i == j)
//DO some work
I have a column in one of my table where I store multiple ids seperated by comma's.
Is there a way in which I can use this column's value in the "IN" clause of a query.
The column(city) has values like 6,7,8,16,21,2
I need to use as
Select * from table where e_ID in (Select city from locations where e_Id=?)
I am satisfied with Crozin's answer, but I am open to suggestions, views and options.
Feel free to share your views.
Say you've got the following query on 9i:
SELECT /*+ USE_HASH(t2 t3) */
* FROM
table1 t1 -- this has lots of rows
LEFT JOIN table2 t2 ON t1.col1 = t2.col1
AND t1.col2 = t2.col2
LEFT JOIN table3 t3 ON t1.col1 = t3.col1
AND t1.col2 = t3.col2
Due to 9i not having RIGHT OUTER HASH JOIN, it needs to hash table1 for both joins. Does it re-hash table1 between joining t2 and t3 (even though it's using the same join columns), or does it keep the same hash information for both joins?
Hi all,
Any idea on how to order the results of a MYSQL query by the sum of two columns rather than by a single column?
Select * FROM table ORDER BY (col1+col2) desc
I know that won't work., but I hope it conveys what I want to do fairly well.
Thanks!
I want to list records with a particular month and year. The table name is 'Arrival' and 'date' is the field that stores the date that the record was added. This is to be done from a C# application. For example, if the user selects month as 'April' and year as '2009' in the application, it will list all the records that were added on April,2009. (I only need the query, hope I can figure out the rest :) )
I've got a table (col1, col2, ...) with an index on (col1, col2, ...). The table has got millions of rows in it, and I want to run a query:
SELECT col1, COUNT(col2) WHERE col1 NOT IN (<couple of exclusions>) GROUP BY col1
Unfortunately, this is resulting in a full table scan of the table, which takes upwards of a minute. Is there any way of getting oracle to use the index on the columns to return the results much faster?
For certain types of sql queries, an auxiliary table of numbers can be very useful. It may be created as a table with as many rows as you need for a particular task or as a user defined function that returns the number of rows required in each query.
What is the optimal way to create such a function?
Here is a table structure (e.g. test):
__________________________________________
| Field Name | Data Type |
|________________|_________________________|
| id | BIGINT (20) |
|________________|_________________________|
| title | varchar(25) |
|________________|_________________________|
| description | text |
|________________|_________________________|
A query like:
SELECT * FROM TEST ORDER BY description;
But I would like to order by the field size/length of the field description. The field type will be TEXT or BLOB.
i need to implement the following query in SQL Server
select *
from table1
WHERE (CM_PLAN_ID,Individual_ID)
IN
(
Select CM_PLAN_ID, Individual_ID
From CRM_VCM_CURRENT_LEAD_STATUS
Where Lead_Key = :_Lead_Key
)
but the WHERE..IN clause allows only 1 column. How to compare 2 or more columns with another inner select?
I have a table:
id, datetime, event
i also have table dates:
date (Y-m-d format)
the problem is some days don't have any events, I would like them to show 0 (or null)
SELECT DATE_FORMAT(table.timestamp, '%Y-%m-%d') ydm, count(table.fkUID) FROM `table` where table.fkUID=$var group by ydm;
is there some way to join or use conditional statements to make the result show:
date|count
----------
2010-05-23| 5
2010-05-24| 0 <--- this line just doesn't exist in my query.
2010-05-26| 3