How can i perform this query in NHibernate for getting child count - performance

select name,
(select count(*) from products where products.category_Id=categories.Id) as productCount
from categories
session.CreateCriteria<Category>()
but whats next?
i don't even know how to search it in Google?

think of your query like
SELECT categories.Id, count(categories.Id)
FROM categories inner join products on products.category_Id=categories.Id
group by categories.Id
I think they will produce the same result.
search google for
nhibernate criteria join
and
CreateAlias

Related

JOIN 4 tables in one (Oracle R11)

I need to create a query that shows the "Legal Entity", "Application Name", "Close Date" and "Period" I'm working with Oracle R11, Right now I've found the query for
"Legal Entity"
SELECT name
FROM hr_organization_information HOI
INNER JOIN hr_all_organization_units HAOU
ON HOI.ORGANIZATION_ID = Haou.Organization_Id
WHERE HOI.org_information_context LIKE 'Legal Entity Accounting'
ORDER BY NAME ASC;
and for "Application Name, Close Date, Period"
SELECT A.APPLICATION_ID,
B.APPLICATION_NAME,
TO_CHAR(A.END_DATE,'HH24:MI DD-MON-YYYYI'),
A.PERIOD_NUM
FROM GL_PERIOD_STATUSES A
INNER JOIN FND_APPLICATION_TL B ON A.APPLICATION_ID = B.APPLICATION_ID
WHERE A.Application_Id=101
AND LANGUAGE='US'
OR A.APPLICATION_ID=200
AND LANGUAGE='US'
OR A.APPLICATION_ID=222
AND LANGUAGE='US';
Separately but I haven't found the way to join them in one query, can you help me with that?
Antonio, I think Brian has given you sound advice. Posting to an EBS forum (or whatever application this is) might also be worthwhile if his advice has not lead you to the answer. I will offer that sometimes the way to join table_A and table_B is through table_C. That is, if you do not find any directly related data in the queries of one se to one of the tables in the other set then look at the FK defined on and pointing to these tables to see if you can find a table not currently part of either query that relates the sets. You figure out how to join each of your current queries to it and that is how you join the two queries together.
Thank you all!
The advices that all of you gave to me were useful, I've found the table HR_LEGAL_ENTITIES (Table C) that have two columns that allow me to join Table A with Table B, the final query was:
SELECT HAOU.NAME,
FAT.APPLICATION_NAME,
TO_CHAR(GPS.END_DATE,'HH24:MI DD-MON-YYYY'),
GPS.PERIOD_NUM
FROM HR_ALL_ORGANIZATION_UNITS HAOU
INNER JOIN HR_LEGAL_ENTITIES HLE
ON HLE.ORGANIZATION_ID = HAOU.ORGANIZATION_ID
INNER JOIN GL_PERIOD_STATUSES GPS
ON HLE.SET_OF_BOOKS_ID = GPS.SET_OF_BOOKS_ID
INNER JOIN FND_APPLICATION_TL FAT
ON GPS.APPLICATION_ID = FAT.APPLICATION_ID
WHERE GPS.Application_Id IN (101,200,222) AND LANGUAGE='US'
ORDER BY NAME ASC;
Regards!

laravel about inner join and subquery

ok, now ,I want get sql just like:
select field1,field2,field3 from orders
inner join
(select id from orders where field4=3 limit 1000, 20)
as temp using(id)
how can I get this by laravel 5.1?
er, sorry I poor in english. What I mean is I want get the native sql like that , and now I don't know what can I do with laravel DB or ORM. I create a model Order corresponding to the table orders.
thank you ~
Although it is not a good way to do it because laravel supports inner joins in query builder. You can do it like this:
DB::select(DB::raw(" select field1,field2,field3 from orders
inner join
(select id from orders where field4=3 limit 1000, 20)
as temp using(id)
"))->get();
Use the following code
DB::select(DB::raw(" select field1,field2,field3 from orders
inner join
(select id from orders where field4=3 limit 1000, 20)
as temp using(id)
"))->get();

HIve join without common filed

I have the following tables:
Table1:
user_name Url
Rahul www.cric.info.com
ranbir www.rogby.com
sahil www.google.com
banit www.yahoo.com
Table2:
Keyword category
cric sports
footbal sports
google search
I want to search Table1 by matching the keyword in Table2. I can perform the same using case statement and the query works but it is not the right approach because each time I have to add the case statement when I will add new search keyword.
select user_name from table1
case when url like '%cric%' then sports
else 'undefined'
end as category
from table1;
Thanks find the soluntions for this approach. FIrst we need to do the Join and after that we need to filter the record.
select user_name,url,Keyword,catagory from(select table1.user_name,table1.url ,table2.keyword,table2.catagory from table1 left outer join table2)a where a.url like (concat('%',a.phrase,'%')
Not sure about more current versions, but I've run into a similar problem... the primary issue is that Hive only supports equi-join statements... when you apply logic to either side of the join, it has difficulty translating into a Map Reduce function.
The alternative method, if you have a reliably structured field, is that you can create a matching key from the larger field. For example, if you know that you're looking for your keyword to exist in the second position of a dot-delimited URI, you could do something like:
select
Uri
, split(Uri, "\\.")[1] as matchKey
from
Table1
join Table2 on Table2.keyword = Table1.matchKey
;

ORACLE Select list inconsistant with group by

I can't create my view and I don't know how to fix it.
when trying to create the view it tries to add all the columns from select to the group by, which isn't what I want. and doesn't work anyways
CREATE OR REPLACE FORCE VIEW CustomerSaleHistoryView AS
Select SALE.SaleID,
SALE.SaleDate,
CUSTOMER.LastName,
CUSTOMER.FirstName,
SALE_ITEM.SaleItemID,
SALE_ITEM.ItemID,
ITEM.ItemPrice,
SUM(SALE_ITEM.ITEMPRICE),
AVG(SALE_ITEM.ITEMPRICE)
from customer
join sale on customer.CUSTOMERID = Sale.CUSTOMERID
join sale_item on sale_item.saleid = sale.saleID
join item on sale_item.itemID = item.itemID
group by CUSTOMER.LastName, CUSTOMER.FirstName, SALE.SaleID;
In order for you query to work you MUST group by any columns that are not being aggregated with a formula like SUM() or AVG(). In your case GROUP BY SALE.SaleID, SALE.SaleDate, CUSTOMER.LastName, CUSTOMER.FirstName, SALE_ITEM.SaleItemID, SALE_ITEM.ItemID, ITEM.ItemPrice
What are you trying to accomplish that you don't believe this GROUP BY is appropriate?
When using group by clause the list of columns that you are selecting should be either part of the group by clause or they should be part of an aggregate function. In your case SALE.SaleDate, SALE_ITEM.SaleItemID, SALE_ITEM.ItemID and ITEM.ItemPrice doesn't satisfy that rule. You need to include these to your group by clause. Once you fix the select statement and when it returns the desired output convert that into a view.

How to JQuery PHP AJAX filter based on multiple checkbox product

I am working on a job site on which jobs will have categories titles like, salary, Sector, Location etc. The idea is to enable a visitor to filter out posts by selecting appropriate checkboxes for all these three categories and show the posts which contains category parameters chosen by the user. Here is an example of what i am looking for : http://underwearking.nl/heren/ (see the left sidebar)
I have gone through over 200 plugins and searched wordpress thoroughly but i am unable to find any plugin which fulfills this. Also, I don't know much about coding but i know that it involves something like integration of jQuery Ajax and checkboxes... Can someone please help me???
Try UNION ALL:::
select distinct wp_usermeta.user_id, wp_users.user_nicename
FROM wp_usermeta
LEFT JOIN wp_users
ON wp_usermeta.user_id=wp_users.ID
ORDER BY wp_usermeta.user_id
UNION ALL
select distinct t1.user_id ,t2.meta_value shop from wp_usermeta as t1, wp_usermeta as t2 where t1.user_id = t2.user_id and ( (t1.meta_key = 'category' and t1.meta_value like '%$catid%') ) and t2.meta_key='shop_name' order by t2.meta_value ASC
You can an extra JOIN to that table p_usermeta in the same query, then LEFT JOIN the wp_users the same way you did, something like this:
SELECT distinct
t1.user_id,
wp_users.user_nicename,
t2.meta_value shop
FROM wp_usermeta AS t1
INNER JOIN wp_usermeta as t2 ON t1.user_id = t2.user_id
LEFT JOIN wp_users ON t1.user_id = wp_users.ID
where ((t1.meta_key = 'category' and t1.meta_value like '%$catid%'))
and t2.meta_key='shop_name'
ORDER BY wp_usermeta.user_id, t2.meta_value
LIMIT 1,10"

Resources